天道酬勤,学无止境

multithreading

Correct handling of background calls in jersey

I have to do some background calls to a web service within a web application. The response of the call is not really time-critical and barely interesting for me. It changes only in rare cases, where I will react to it by throwing a exception, or logging the failure or something. My conrete question now refers to the correct handling of such asynch calls in Jersey Client 2. Option 1 uses the async calls from jersey, but then starts a thread for each response. Option 2 would immediatly start a thread and use jersey from inside this thread. Generally which option would be more adviseable? Option

2022-01-19 02:37:35    分类:问答    java   multithreading   jax-rs   jersey-2.0   jersey-client

Python/Tkinter: Are Tkinter StringVar (IntVar, etc) thread safe?

Are Tkinter StringVar (IntVar, FloatVar, etc) thread safe, eg. can a background thread read or write to these objects? Or must I use a Queue to pass information between my background thread and my main Tkinter GUI thread and have my main Tkinter thread pop the Queue and update the application's StringVar's accordingly? I know my application's background threads must not read or write a Tkinter widget directly but I'm unclear on whether StringVar's (or their ilk) are considered widgets or if they are objects far enough removed from widgets that they are thread safe for background threads to

2022-01-19 02:28:38    分类:问答    python   multithreading   user-interface   tkinter

concurrent access and free of a data structure

The problem is like this: I have an array of 500 pointers which point to 500 elements in a doubly linked list. There are 10 threads which run in parallel. Each thread runs 50 loops, and tries to free some element in the list. The list is sorted (contain simple integers), and there are 10 other threads running in parallel, searching for the node that contains a particular integer and access the other satellite data in this node. So the node is like: struct node { int key; // Key used to search this nodes int x,y,z; // Satellite data struct node *prev; struct node *right; }; The problem is

2022-01-19 01:45:11    分类:问答    c   multithreading   memory-management   concurrency

How can I protect a vector with a Mutex?

I am working on designing a C++ server that accepts multiple different interacting clients, and I use vectors to keep track of all of them individually. However, I realized that, because of so many threads running, there's a tiny chance a vector might be read and written to at the same time by two threads. Is there a quick and safe way to add a mutex or something to them so that it will wait until all the reads are done until another function adds to it? Not doing so can mess up the protocol and maybe even crash the server. I had an idea to create a global variable that would lock all reads to

2022-01-19 00:44:46    分类:问答    c++   windows   multithreading   vector   mutex

How to "safely publish" lazily-generated effectively-immutable array

Java's present memory model guarantees that if the only reference to an object "George" is stored into a final field of some other object "Joe", and neither George nor Joe have never been seen by any other thread, all operations upon George which were performed before the store will be seen by all threads as having been performed before the store. This works out very nicely in cases where it makes sense to store into a final field a reference to an object which will never be mutated after that. Is there any efficient way of achieving such semantics in cases where an object of mutable type is

2022-01-19 00:39:33    分类:问答    java   multithreading   final

What is the absolute fastest way to implement a concurrent queue with ONLY one consumer and one producer?

java.util.concurrent.ConcurrentLinkedQueue comes to mind, but is it really optimum for this two-thread scenario? I am looking for the minimum latency possible on both sides (producer and consumer). If the queue is empty you can immediately return null AND if the queue is full you can immediately discard the entry you are offering. Does ConcurrentLinkedQueue use super fast and light locks (AtomicBoolean) ? Has anyone benchmarked ConcurrentLinkedQueue or knows about the ultimate fastest way of doing that? Additional Details: I imagine the queue should be a fair one, meaning the consumer should

2022-01-19 00:37:38    分类:问答    java   multithreading   optimization   concurrency   real-time

Is the following java code thread safe without volatile?

public static Singleton singleton; public static Singleton get(){ synchronized (Singleton.class) { if (singleton == null) { singleton = new Singleton(); } } return singleton; } Some one say that no volatile for singleton variable is wrong. But I think this is the right code for singleton object creation. I want to know whether this code has a thread safety or not?

2022-01-19 00:32:50    分类:问答    java   multithreading   parallel-processing   synchronization   volatile

Write to excel file with multiple threads

I am trying to write to datatable to excel which has large records. I am trying to achieve using divide and conquer strategy where each thread is assigned to write to respective sheets of excelworkbook.but I am getting file is readonly ,click Ok to override the file. class Program { int processorCount = 2; static volatile bool processing = true; DataTable employeeTable = new DataTable("Employee"); ManualResetEvent mre = new ManualResetEvent(false); AutoResetEvent ar = new AutoResetEvent(true); int record_count; static void Main(string[] args) { Program p = new Program(); //Create an Emplyee

2022-01-19 00:17:45    分类:问答    c#   multithreading   excel   export-to-excel   excel-interop

Why does a parallel stream processing with lambda in the static initializer block with forEachOrdered produces a deadlock, but not with forEach?

While playing with Java parallel streams, I experienced deadlocks when some parallel operations are done within a static initializer block. When using a sequential Stream, everything works fine: import java.util.Arrays; public class Example1 { static { // displays the numbers from 1 to 10 ordered => no thread issue Arrays.asList(1,2,3,4,5,6,7,8,9,10) .forEach(s->System.out.println(s)); } public static final void main(String[] args) {} } When processing the stream in parallel, everyting work (the numbers are displayed without order): import java.util.Arrays; public class Example2 { static { //

2022-01-18 23:07:01    分类:问答    java   multithreading   lambda   foreach   java-stream

Is it possible to halt the execution of all other threads when reaching a breakpoint in gdb?

So, as soon as I hit a breakpoint in some thread, is it possible to halt other threads until I continue?

2022-01-18 23:04:30    分类:问答    multithreading   debugging   gdb