liveBook · Manning

Logical thread

As explained in Grokking Concurrency

A user-level thread is a thread managed by a user-space runtime or library rather than directly by the operating system.

A logical thread is a user-level thread managed by an application, runtime, or library rather than directly by the operating system. The OS sees the application as a single-threaded process, while the runtime organizes several tasks within it. These threads commonly support cooperative multitasking: each task explicitly yields control so another task can run. section 12.3

Logical threads trade operating-system control for lightweight, cooperative task management:

  • Use fewer resources: switching tasks can cost little more than calling a function, making millions of coroutines possible without significant management overhead. section 12.5
  • Avoid interrupting critical sections by choosing explicit points where tasks may hand control to one another. section 12.5
  • Require disciplined yielding: a long-running task can prevent every other task from running because the scheduler cannot forcibly take control. section 12.3 section 12.5

Many I/O tasks on one worker

A server can use a small number of operating-system threads to coordinate many I/O-related tasks. Each task performs a small portion of work, yields, and later resumes. This can improve resource utilization and scalability, provided no task holds control for too long. section 12.5 section 12.12

Logical threads are one implementation of asynchronous systems. Coroutines represent partially executed functions that pause and resume, while futures represent results that are not yet available. section 12.12

How Grokking Concurrency covers it

How deep it goes
Explains scheduling behavior, switching costs, resource sharing, and yielding, but stops short of implementation code.
Examples
Uses millions of coroutines, single-threaded scalable applications, and I/O-heavy servers and databases as concrete applications.
What you can do after
Evaluate when lightweight cooperative tasks suit concurrent I/O workloads and recognize the danger of failing to yield.
How it connects
Connects user-level threads with cooperative multitasking, preemptive multitasking, coroutines, futures, and asynchronous communication.

Also explained in

Compare how 3 books explain logical thread →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Concurrency. The section links point to the parts of the book it draws on.