The Core Difference: Memory

AspectProcessThread
Memory spaceOwn isolated address spaceShares memory with other threads in the same process
CommunicationIPC — pipes, sockets, shared memory (slow)Direct shared variables (fast)
Creation costExpensive — OS allocates new address spaceCheap — reuses parent process's memory
Crash isolationOne process crashing doesn't affect othersOne thread crashing can corrupt the whole process
Context switchExpensive — swaps memory page tablesCheaper — same address space, just swaps registers/stack
AnalogySeparate housesRoommates sharing one house

A Process Owns Resources; Threads Use Them

When the operating system starts a program, it creates a process with its own:

  • Virtual memory address space (code, heap, stack)
  • File descriptors and open handles
  • Environment variables and security context

A process can then spawn one or more threads, each with its own call stack and program counter (so each thread can be paused/resumed independently), but all threads share the same heap, file descriptors, and global variables.

Why Threads Are Risky: Shared Memory

Because threads share memory, two threads writing to the same variable at the same time causes a race condition unless protected by synchronization (locks, mutexes, semaphores). This is the trade-off: threads communicate fast because they share memory, but that same sharing is the source of the hardest bugs in concurrent programming — and the reason a single thread's crash can bring down the entire process.

Multithreading vs Multiprocessing

AspectMultithreadingMultiprocessing
Best forI/O-bound work (waiting on network/disk)CPU-bound work (heavy computation)
Memory overheadLow — shared memoryHigher — each process has its own memory
True parallelismDepends on language (blocked by GIL in CPython)Yes — each process can run on its own CPU core
Fault toleranceLower — shared state, shared crash domainHigher — isolated crash domain

Node.js: "Single-Threaded" but Not Quite

Node.js runs your JavaScript on a single main thread, driven by an event loop that handles asynchronous I/O without blocking. This is why a single slow synchronous computation can freeze an entire Node.js server — there's no second thread to pick up other requests while it runs.

Under the hood, Node uses a libuv thread pool for things like file system calls and DNS lookups, and exposes the worker_threads module for genuinely parallel CPU-bound work — but your application code itself executes on one thread unless you explicitly opt into workers.

⚠️ Python's GIL Limits Threading for CPU-Bound Work

CPython's Global Interpreter Lock (GIL) allows only one thread to execute Python bytecode at a time. Multithreading still helps for I/O-bound tasks (the GIL is released during I/O waits), but for CPU-bound parallelism, Python developers reach for the multiprocessing module instead, trading shared-memory speed for true multi-core execution.

Context Switching Cost

Switching the CPU from running one thread/process to another requires saving and restoring state. Process switches are more expensive because the CPU must also reload the memory page table — threads within the same process skip this since they already share the same address space. This is part of why thread pools and async I/O are often preferred over spawning many OS processes for highly concurrent servers.

💡 Rule of Thumb

Reach for threads when tasks need to share data frequently and you can manage synchronization carefully. Reach for processes when you need fault isolation, true CPU parallelism, or are running untrusted/independent workloads.

How We Research and Update This Guide

We test the underlying formula or workflow, compare outputs with reliable references, and revise examples whenever the page content changes.

  • The workflow or formula is tested directly in the tool and compared against independent reference examples.
  • Examples are kept practical so readers can verify the result without hidden assumptions.
  • Pages are revised whenever the interface, calculation flow, or surrounding guidance materially changes.

Frequently Asked Questions — Thread vs Process