Re-creating threading and concurrency knowledge in increasingly popular languages

I am primarily a Java developer, and I've been reading a lot of in-depth work on threads and concurrency. Many very smart people (Doug Lea, Brian Goetz, etc) have authored books on these topics...

Review request: Thread safe queue (parallel push pop)

Here is an implementation of a thread safe queue. The push and pop won't block each other. However, pop will wait until an item is pushed, if the queue is empty. Multiple producers and consumers...

How to dump or search in call stacks of ALL threads in Visual Studio

How to dump or search in call stacks of ALL threads in Visual Studio? We have a server process to debug and it has hundreds of threads running, so it should be hard to manually check each...

What is the difference between concurrency, parallelism and asynchronous methods?

Concurrency is having two tasks run in parallel on separate threads. However, asynchronous methods run in parallel but on the same 1 thread. How is this achieved? Also, what about...

When should I use a CompletionService over an ExecutorService?

I just found CompletionService in this blog post. However, this does't really showcases the advantages of CompletionService over a standard ExecutorService. The same code can be written with...

How to get the return value from a thread in python?

The function foo below returns a string 'foo'. How can I get the value 'foo' which is returned from the thread's target? from threading import Thread def foo(bar): print('hello...

What could be the cause of RejectedExecutionException

I am getting this exception on my tomcat server (+liferay) java.util.concurrent.RejectedExecutionException my class is like that : public class SingleExecutor extends ThreadPoolExecutor { ...

Are Parallel.Invoke and Parallel.ForEach essentially the same thing?

And by "same thing" I mean do these two operations basically do the same work, and it just boils down to which one is more convenient to call based on what you have to work with? (i.e. a list of...

How would you implement your own reader/writer lock in C++11?

I have a set of data structures I need to protect with a readers/writer lock. I am aware of boost::shared_lock, but I would like to have a custom implementation using std::mutex,...

log analyze: finding lines by time difference

I have a long log file generated with log4j, 10 threads writing to log. I am looking for log analyzer tool that could find lines where user waited for a long time (i.e where the difference between...

Using C++11 thread with pure virtual thread function

I have code where objects that are intended to execute in separate thread derive from a base class with a pure virtual Run function. I cannot get the following (simplified test code) to run the...

How is CountDownLatch used in Java Multithreading?

Can someone help me to understand what Java CountDownLatch is and when to use it? I don't have a very clear idea of how this program works. As I understand all three threads start at once and each...

How to create threads in nodejs

Is there any way to create threads for running multiple methods at a time? That way, if any method fails in between all the other threads should be killed.

Volatile variable explanation in Java docs

when a thread reads a volatile variable, it sees not just the latest change to the volatile, but also the side effects of the code that led up the change This is mentioned at...

Need to understand the usage of SemaphoreSlim

Here is the code I have but I don't understand what SemaphoreSlim is doing. async Task WorkerMainAsync() { SemaphoreSlim ss = new SemaphoreSlim(10); List<Task> trackedTasks = new...

About thread-safety of weak_ptr

std::shared_ptr<int> g_s = std::make_shared<int>(1); void f1() { std::shared_ptr<int>l_s1 = g_s; // read g_s } void f2() { std::shared_ptr<int> l_s2 = std::make_shared<int>(3); std::thread...

Lock-free C++ data structures, impossible?

I really dont understand how you can make some data structures lock-free. For example, if you have a linked list then either you surround the operations with mutexes, OR you can end up with a race...

Can num++ be atomic for 'int num'?

In general, for int num, num++ (or ++num), as a read-modify-write operation, is not atomic. But I often see compilers, for example GCC, generate the following code for it (try here): void f() { ...

Task.Run from UI thread throws STA error

While I was refactoring some old C# code for document generation with Office.Interop library I found this and because of it was using UI context when function were called from it it was blocking...

In which thread do CompletableFuture's completion handlers execute?

I have a question about CompletableFuture method: public <U> CompletableFuture<U> thenApply(Function<? super T, ? extends U> fn) The thing is the JavaDoc says just this: Returns a new...

dotnet core equivalent to Thread.Abort

Background I have a Service abstraction. Each service has it own WorkItem. WorkItem able to start with some data. The service is limiting the excution time of WorkItem. Let's say that a single...

Delphi crSQLWait mouse cursor issue

We have legacy delphi application in which entire code is in main thread only. In one of the function, we are calling service layer function to fetch database records. Before requesting the...

How to distinguish RUNNING state from java.lang.Thread.State.RUNNABLE in Java

When a thread is RUNNABLE, it can be running, or be not. Is there a way to distinguish it from java.lang.Thread.State#RUNNABLE? All states of threads in Java doc: java.lang public class...

how to stream multiple camera feeds to single socket in python

I am working on a module where i have to detect some predefined objects in the video stream. For object detection i am using YOLO. I need to process multiple camera feeds in parallel. I tried...

Understanding `memory_order_acquire` and `memory_order_release` in C++11

I'm reading through the documentation and more specifically memory_order_acquire: A load operation with this memory order performs the acquire operation on the affected memory location: no reads...

Java scheduleAtFixedRate + Thread.sleep

I'm just exploring method scheduleAtFixedRate of class ScheduledExecutorService in Java. Here is my suspicious code: ScheduledExecutorService scheduledExecutorService =...

IntelliJ IDEA change default breakpoint suspend policy

I'm migrating from Eclipse to IntelliJ IDEA 2020.1.1. In Eclipse, when adding a new breakpoint default suspend policy is to stop for current thread. In IntelliJ it is suspend all threads. Does...

Threading reading a serial port in Python (with a GUI)

I want to trigger an event whenever there is data to be read from a serial port while running a GUI. The pySerial module apparently has experimental functionality for that, but it isn't...

Why not to use synchronized ArrayList even in single thread cases?

I have run the following code to measure the time and performance difference between adding elements to ArrayList vs synchronized version of it, and surprisingly haven't find any significant...