01 - Concurrency Models Compared: Thread OS, Event Loop, Goroutine, Actors and Async/Await
A thousand 100 ms waits cost 10 seconds with 10 threads and 0.1 with an event loop; four computations on one JS thread cost 12. Choose a model by measuring.
Ten articles on concurrency with executed tests: event loop, goroutines, asyncio, virtual threads, Rust, race conditions, lock-free and distributed systems.
This series collects 10 articles (approximately 147 minutes of total reading time), designed for a level Advanced. The main topics covered are goroutine, event loop, concorrenza, thread.
A thousand 100 ms waits cost 10 seconds with 10 threads and 0.1 with an event loop; four computations on one JS thread cost 12. Choose a model by measuring.
Why a Promise beats setTimeout at 0 ms and a long loop freezes Node.js: call stack, microtasks and macrotasks explained with programs that were run.
Goroutines, channels, select, context and WaitGroup in Go: how to start, stop and wait for concurrent work, with failure cases and the race detector.
gather leaves orphaned tasks when one fails, TaskGroup cancels them: errors, except*, cancellation and timeouts in asyncio, with programs that were run.
Java 21 virtual threads make waiting cheap, but synchronized pinning costs 4x on Java 21 and StructuredTaskScope is still a preview: tried on JDK 21 and 25.
A Rust async fn does nothing until someone polls it: Future, Pin and Waker with a mini-runtime, then Tokio with select!, channels and cancellation.
counter++ loses increments, a synchronized method cannot stop a negative balance and two crossed locks freeze everything: experiments in Java and C with TSan.
CAS loop, Treiber stack, Michael-Scott queue, ABA and memory ordering tried with Java and C++ programs that were run: where lock-free works and where not.
An unbounded queue makes the last item wait almost 3 seconds: bounded queues, Reactive Streams, Reactor and asyncio to handle a producer that is too fast.
CAP constrains only during the partition: quorum, vector clocks, CRDTs and sagas explained with Python simulations that were run, and where LWW loses an update.