What is a coroutine?

Coroutines and concurrency are largely orthogonal. Coroutines are a general control structure whereby flow control is cooperatively passed between two different routines without returning. The ‘yield’ statement in Python is a good example. It creates a coroutine. When the ‘yield ‘ is encountered the current state of the function is saved and control is returned … Read more

Choosing the best concurrency list in Java

had better be List The only List implementation in java.util.concurrent is CopyOnWriteArrayList. There’s also the option of a synchronized list as Travis Webb mentions. That said, are you sure you need it to be a List? There are a lot more options for concurrent Queues and Maps (and you can make Sets from Maps), and those structures tend to make the most sense for many of the … Read more

Collection was modified; enumeration operation may not execute

What’s likely happening is that SignalData is indirectly changing the subscribers dictionary under the hood during the loop and leading to that message. You can verify this by changing To If I’m right, the problem will disappear. Calling subscribers.Values.ToList() copies the values of subscribers.Values to a separate list at the start of the foreach. Nothing else has access to this list (it … Read more

What’s the difference between the message passing and shared memory concurrency models?

It’s a pretty simple difference. In a shared memory model, multiple workers all operate on the same data. This opens up a lot of the concurrency issues that are common in parallel programming. Message passing systems make workers communicate through a messaging system. Messages keep everyone seperated, so that workers cannot modify each other’s data. … Read more

What are atomic operations for newbies?

Pretty much, yes. “Atom” comes from greek “atomos” = “uncuttable”, and has been used in the sense “indivisible smallest unit” for a very long time (till physicists found that, in fact, there are smaller things than atoms). In concurrent programming, it means that there will be no context switch during it – nothing can affect the execution … Read more

What is the difference between concurrency and parallelism?

Concurrency is when two or more tasks can start, run, and complete in overlapping time periods. It doesn’t necessarily mean they’ll ever both be running at the same instant. For example, multitasking on a single-core machine. Parallelism is when tasks literally run at the same time, e.g., on a multicore processor. Quoting Sun’s Multithreaded Programming Guide: Concurrency: A condition that exists when at least two … Read more