Skip to main content

Concurrency

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.

10Articles147 minTotal reading timeAdvancedLevel
goroutineevent loopconcorrenzathreadactor modelcall stack

Series Articles

  1. 1

    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.

  2. 2

    02 - JavaScript Event Loop: How It Really Works, Call Stack, Microtask and Macrotask

    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.

  3. 3

    03 - Goroutine and Channel in Go: Practical Competition with Communicating Sequential Processes

    Goroutines, channels, select, context and WaitGroup in Go: how to start, stop and wait for concurrent work, with failure cases and the race detector.

  4. 4

    04 - Async/Await Advanced Python: asyncio Internals, TaskGroup and Robusta Cancellation

    gather leaves orphaned tasks when one fails, TaskGroup cancels them: errors, except*, cancellation and timeouts in asyncio, with programs that were run.

  5. 5

    05 - Java Virtual Threads (Project Loom): Thread Platform vs Virtual Threads and Structured Concurrency

    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.

  6. 6

    06 - Rust Async and Tokio: Future, Pin, Waker and the Zero-Cost Concurrency Model

    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.

  7. 7

    07 - Race Condition and Deadlock: How to Recognize, Diagnose and Prevent Them

    counter++ loses increments, a synchronized method cannot stop a negative balance and two crossed locks freeze everything: experiments in Java and C with TSan.

  8. 8

    08 - Lock-Free Data Structures: Atomic Operations, Memory Ordering and Compare-and-Swap

    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.

  9. 9

    09 - Backpressure and Flow Control: Managing the Case Where the Producer Outperforms the Consumer

    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.

  10. 10

    10 - Distributed Systems and Concurrency: CAP Theorem, Consistency Models and CRDT

    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.