Implementation Detail

  • Building blocks of strategies.

Worker

  • "A thread, fiber, or goroutine that executes jobs."

Scheduler and Task Queue

  • "Decides which worker gets which task."

  • Not needed for Dedicated Threads.

Task Queue
  • "Holds pending work (FIFO, priority-based, etc.)."

Work Stealing
  • A scheduler optimization (workers steal tasks from others).

Coroutine

  • A coroutine is a general programming construct that allows a function to suspend execution and resume later, preserving its state.

  • Usually used in single-threaded environments.

  • Cooperative control

    • A coroutine must explicitly yield control back to the caller or scheduler.

  • Resumable state

    • Each coroutine has its own execution context and stack.

  • Use Case

    • Asynchronous I/O

    • Event loops

    • Cooperative multitasking

  • Examples :

    • Python ( async/await , generators), Kotlin, Lua, C++, C#, JavaScript ( async/await ), etc.

Types
  • Stackless coroutines :

    • Use language support and compiler transformations (e.g., async/await  in JavaScript).

  • Stackful coroutines :

    • Can suspend from deeper in the call stack (e.g., Lua, Boost.Coroutine in C++).

Asynchronous Programming (Async)

Clarification
  • Async Programming is a paradigm (like event-driven code), not strictly an "implementation detail." It can be a strategy (e.g., Node.js’s event loop) or a tool (e.g., async/await  with threads). It's often implemented via callbacks/futures/coroutines.

  • Async is a programming model that allows non-blocking execution of tasks using event loops and callbacks/futures.

  • Can be concurrent, but not inherently parallel .

  • Tasks can pause and resume without blocking threads.

  • Optimized for I/O-bound workloads.

  • Abstracts event-driven state machines.

Examples
  • Sending an HTTP request without blocking the main thread while waiting for the response.

  • One worker that starts a task , and when waiting, does something else  instead of blocking.