Fundamentals 8 min read

Demystifying Concurrency: From Threads to Coroutines and Monitors

This article clarifies core operating‑system concepts such as tasks, jobs, hyper‑threading, threads, processes, fibers, monitors, and coroutines, explaining their differences, relationships, and how they enable efficient concurrent execution.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Demystifying Concurrency: From Threads to Coroutines and Monitors

Related Concepts

Task, Job, Schedule

Before the notion of a process existed, these terms were used to describe units of work.

1. Hyper‑Threading

Hyper‑Threading is an Intel CPU design technique that allows a single physical core to execute two threads simultaneously, reducing the overhead of thread switching.

2. Thread

A thread is a lightweight unit of execution that can run independently and be scheduled separately from a process, sharing most of the process's resources.

Threads are lighter than processes.

Threads have their own execution context (e.g., CPU registers, program counter).

Thread scheduling incurs far less overhead than process scheduling.

Multiple threads within the same process share the process's resources.

3. Process

A process is an operating‑system abstraction representing a running program, consisting of code, data, and its own execution context. The OS can run multiple processes concurrently, each requiring resources such as CPU time, memory, and I/O devices.

A process is an abstract structure for a running program.

It is the basic unit of resource allocation.

Multiple processes can execute concurrently and exchange information.

Processes need resources like CPU, storage, and I/O devices.

4. Fiber

Fibers are user‑mode lightweight threads introduced by Microsoft to improve code portability across platforms. Unlike kernel threads, fibers are scheduled by the application, not the OS.

Threads are scheduled by the OS kernel; fibers run in user mode.

A thread can contain one or more fibers.

Kernel scheduling is pre‑emptive for threads; only one fiber runs at a time per thread.

Fiber scheduling is independent of thread scheduling and can be pre‑empted by the OS.

Windows provides APIs to convert threads to fibers or create multiple fibers within a thread.

5. Monitor

A monitor is a synchronization construct that encapsulates shared resources and the procedures that operate on them, ensuring that only one process accesses the critical resource at a time.

Critical resources allow only one process to access them at a time.

Semaphores require each process to perform wait and signal operations, which can lead to scattered synchronization code and potential deadlocks.

Monitors solve this by bundling the resource and its access procedures into a single module.

6. Coroutine (Co‑routine)

Coroutines are user‑mode lightweight threads; the OS kernel is unaware of them.

Scheduling of coroutines is entirely controlled by the application.

A thread can contain one or more coroutines.

Coroutines maintain their own register context and stack, which are saved and restored on switches.

Coroutines preserve state between calls, similar to generators.

In Windows, coroutines are called fibers.

References

《深入理解计算机系统》 第二版

《Windows 核心编程》 第五版

《计算机操作系统》 第三版

《操作系统概念》 第七版

《计算机程序设计艺术》 卷一

Coroutine – Wikipedia

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

concurrencyCoroutinesprocessesThreads
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.