Threads and Processes
Program vs process vs thread, and the three "multis" (multiprogramming, multiprocessing, multithreading): the units every concurrency discussion is built from.
Seedtended planted 1 min read
🌱 A rough idea, planted recently. Expect rough edges — it will grow.
On this page
Most concurrency confusion comes from blurring three words, so it’s worth pinning them down:
- A program is code sitting on disk.
- A process is a program that’s running, with its own memory space.
- A thread is a unit of execution inside a process. Threads share the process’s memory.
The three “multis”
- Multiprogramming: many processes on one CPU, interleaved so it looks like they run together.
- Multiprocessing: many CPUs or cores, so work genuinely runs in parallel.
- Multithreading: many threads in one process. They’re cheap to create and switch between because they share memory, and that sharing is exactly why they need Synchronization.
Why it matters
Shared memory is fast and dangerous: two threads updating the same value can interleave in ways nobody intended (a race condition). There are two ways out. You can guard shared state with locks, or avoid sharing altogether and use Message Passing.
In practice
- JavaScript is single-threaded with an event loop.
async/awaitis concurrency without parallelism, and Web Workers (or Node worker threads) are how you get real threads, which communicate by message passing. - Rust’s ownership rules make data races a compile-time error rather than a 3am incident.
- Real-time UIs live this every day: keep the main thread free for rendering and push heavy work (parsing a firehose of updates, layout calculations) somewhere else.
Related: Synchronization · Deadlock and Starvation · Message Passing
- #concurrency
- #threads
- #processes
- #operating-systems
↩ Linked from (2)
Related: Synchronization · Threads and Processes · Types of Failure · Fallacies of Distributed Computing
- SynchronizationSeed
When threads touch a shared resource, some interleavings of their steps are fine and some corrupt your data. Synchronisation is the toolbox for allowing only the safe ones.
↪ Links to (3)
Related by topic
- Evergreen
Architecture Decision Records
Career - Growingmetaphor
Balance Is a Control Loop
Calisthenics Lab - Evergreen
CAP Theorem
Distributed systems - Evergreen
Fallacies of Distributed Computing
Distributed systems