Threads vs. Processes
A process has its own address space. Threads of the same process share the heap but have their own stacks. In Java, threads are started through the Thread or Executor services.
Concurrency enables parallelism on multi-core systems but requires synchronization.
Where used
Web worker pools, parallel requests, background jobs. Processes isolate address spaces (security, crash); threads share the heap and require synchronization.
Depth
Processes have separate virtual address spaces and are more strongly isolated from each other by the operating system. Communication requires explicit mechanisms such as pipes, sockets, or shared memory. A failure in one process does not easily corrupt the data of another.
Threads of a process see the same objects and resources but have their own call stacks and register states. The exchange is therefore efficient, but synchronization obligations arise. The choice depends on isolation, communication costs, and the nature of the work.
Difficulty levels
- Distinguishing between separate and shared states.
- Weighing communication and fault isolation costs.
- Assigning a CPU- or I/O-intensive task to a suitable structure.
Pitfalls
Threads do not necessarily run simultaneously but can only be time-multiplexed. Multiple processes also do not guarantee acceleration if communication or resource scarcity dominates.
Tasks
Card Info
- Topic: Algorithms and Data Structures
- Difficulty: Beginner
- Completed: 0 users