What is a thread?
A process can do more than one thing at a time by running several threads. If a process is a kitchen, a thread is a cook. One cook can only do one task at a time — but put three cooks in the same kitchen, sharing the same counters and ingredients, and the dish comes together faster. Threads are how a single program juggles many tasks at once.
Cooks sharing one kitchen
Think about a video call app. While it's running (one process), it needs to do several things AT THE SAME TIME: show your friend's video, send your video, play the audio, and watch for you clicking 'mute'. If it did these one after another, the call would stutter. So the process runs several threads — one per task. Each thread is a separate line of work, but they all live inside the same process and share its memory. That's the key difference from processes: separate processes each have their OWN walled-off memory, but threads inside one process SHARE memory. Same kitchen, same ingredients.
Threads share; processes don't
This sharing is the whole point — and also the whole danger. The good: because threads share memory, they can work on the same data together cheaply, and starting a new thread is much lighter than starting a whole new process. The video app's threads can all see the same call data instantly. The catch: when several cooks reach for the same ingredient at the same moment, they can collide — two threads changing the same value at once and corrupting it. That's a 'race condition', and it's exactly why the OS needs locks (both are topics coming up). Sharing makes threads fast AND makes them need careful rules.
It's a tradeoff
| Option | 👍 Pro | 👎 Con |
|---|---|---|
| Multiple threads (one process) | Lightweight to start; share memory so they cooperate on the same data instantly. | Shared memory means they can collide (race conditions) — you need locks to stay safe. |
| Multiple processes | Fully isolated — one crashing or misbehaving can't corrupt the others' memory. | Heavier to start, and sharing data between them is more work (they don't share memory). |
Questions you might have
▸Is a thread just a smaller process?
Sort of, but the real difference is memory. Processes each get their OWN private memory. Threads live inside one process and SHARE its memory. So threads are lighter and can cooperate easily — but they have to be careful not to step on each other.
▸Why would one program want several threads?
To do things at once without freezing. A browser uses one thread to scroll the page smoothly while another loads images and another runs a video — so the page never locks up waiting on one slow task.
▸If threads share memory, what could go wrong?
Two threads might change the same value at the same time and corrupt it — a 'race condition'. That's a whole topic coming up, along with 'locks' (the fix that lets only one thread touch shared data at a time).
▸Does more threads always mean faster?
No. Threads still share the CPU — if there's only one CPU core, they take turns, so ten threads don't make it ten times faster. Threads help most when tasks spend time waiting (for the network, the disk) so others can use the CPU meanwhile.
Best read after: Process vs. program