concurrent-programming

Javafx Updating UI from a Thread without direct calling Platform.runLater

﹥>﹥吖頭↗ 提交于 2019-12-19 08:33:28
问题 Nowadays some says it is not suitable to use Platform.runLater() for updating the UI from a non-JavaFX Thread and Oracle site introduce a way with bindings for progress bar updating. Here I want to update a Label, so coded it like this: Task task = new Task() { @Override protected Object call() throws Exception { int i = 0; while (true) { this.updateMessage("Count " + i); System.out.println(i); // Thread.sleep(10); i++; } } }; Thread t = new Thread(task); lbStatus.textProperty().bind(task

Javafx Updating UI from a Thread without direct calling Platform.runLater

不羁岁月 提交于 2019-12-19 08:33:14
问题 Nowadays some says it is not suitable to use Platform.runLater() for updating the UI from a non-JavaFX Thread and Oracle site introduce a way with bindings for progress bar updating. Here I want to update a Label, so coded it like this: Task task = new Task() { @Override protected Object call() throws Exception { int i = 0; while (true) { this.updateMessage("Count " + i); System.out.println(i); // Thread.sleep(10); i++; } } }; Thread t = new Thread(task); lbStatus.textProperty().bind(task

Blocking Locks versus Non-Blocking Locks

北城以北 提交于 2019-12-19 08:14:44
问题 I am thinking here: If you have 2 threads executing FAST operations that need to be synchronized, isn't a nonblocking approach faster/better than a blocking/context switch approach? By non-blocking I mean something like: while(true) { if (checkAndGetTheLock()) break; } The only thing I can think of is starvation (with CPU burn out) if you have too many threads looping around the lock. How do I balance one approach versus the other? 回答1: Here's what Java Concurrency in Practice says about the

What's the difference of the usage of volatile between C/C++ and C#/Java?

断了今生、忘了曾经 提交于 2019-12-18 10:29:47
问题 I found it in many references which mention that volatile in C/C++ is is weak and may cause issue in concurrent environment on multiple processor, but it ( volatile ) can be used as communication mechanism between difference CPUs in C#/Java. It seems this keyword is more strict in C#/Java than in C/C++, but what's the difference/impact between them? Here is an reference of volatile in C/C++. Why is volatile not considered useful in multithreaded C or C++ programming? 回答1: For C#/Java , "

Java blocking issue: Why would JVM block threads in many different classes/methods?

流过昼夜 提交于 2019-12-17 23:36:44
问题 Update: This looks like a memory issue. A 3.8 Gb Hprof file indicated that the JVM was dumping-its-heap when this "blocking" occurred. Our operations team saw that the site wasn't responding, took a stack trace, then shut down the instance. I believe they shut down the site before the heap dump finished. The log had no errors/exceptions/evidence of problems--probably because the JVM was killed before it could generate an error message. Original Question We had a recent situation where the

How to explain the “deadlock” better?

老子叫甜甜 提交于 2019-12-17 21:53:45
问题 I am struggling to explain "deadlock" in threads in easy words, so please help. What could be the best example of "deadlock" (say, in Java), and how it does happen in steps and how to prevent it? But without getting into details too deep. I know that's like asking two opposite things, but still. If you have any previous concurrent programming training experience -- it would be superb! 回答1: Jack and Jill happens to want to make a sandwich at the same time. Both need a slice of bread, so they

Concurrent routines in Go

雨燕双飞 提交于 2019-12-13 19:07:15
问题 I want to write three concurrent routines that sends integer to each other. Now, I have implemented two concurrent routines which sends integers to each other. package main import "rand" func Routine1(commands chan int, responses chan int) { for i := 0; i < 10; i++ { i := rand.Intn(100) commands <- i print(<-responses, " 1st\n"); } close(commands) } func Routine2(commands chan int, responses chan int) { for i := 0; i < 1000; i++ { x, open := <-commands if !open { return; } print(x , " 2nd\n")

How can I know which ViewController is active?

萝らか妹 提交于 2019-12-12 22:33:44
问题 I am downloading images using NSOperationQueue. I want to call a method reloadView of my view controller once the image download is complete. However when the download is in progress, it is fairly possible that user has moved to a different view. This other view will also have a reloadView method (e.g. first view shows total downloaded images count, and second shows thumbnails of download images) Basically what I want is that whenever an image download is completed, I should be able to call

Go Programming Language Mutual Concurrent Execution

馋奶兔 提交于 2019-12-12 17:53:20
问题 I have two concurrent go routines like below, Routine 1{ routine procedure critical section{ } routine procedure } Routine 2{ routine procedure critical section{ } routine procedure } Is it possible by using some go inbuilt functions to implement critical section ? 回答1: Your question: I have N concurrent go routines (all more or less same purpose). Each of those have a critical section. Before entering critical section, each routine just do some message sending job. When it enters critical

Go memory consumption with many goroutines

不想你离开。 提交于 2019-12-12 10:38:44
问题 I was trying to check how Go will perform with 100,000 goroutines. I wrote a simple program to spawn that many routines which does nothing but print some announcements. I restricted the MaxStack size to just 512 bytes. But what I noticed was the program size doesn't decrease with that. It was consuming around 460 MB of memory and hence around 4 KB per goroutine. My question is, can we set max stack size lower than the "minimum" stack size (which may be 4 KB) for the goroutines. How can we set