- Forward


Threads and Processes
A Comparison


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

Review
Back SMYC Forward
  • Multi-Processing:
    • Concurrent programs can involve multiple processes
  • Multi-Threading:
    • Concurrent programs can involve multiple threads
Advantages of Threads
Back SMYC Forward
  • Data Sharing:
    • Threads can share data using variables with file scope (processes need to use an IPC mechanism like a file, pipe/FIFO, shared memory segment, message queue, etc..)
  • Speed:
    • Threads can be created more quickly than processes
    • Context switches may be faster for threads than processes
Advantages of Processes
Back SMYC Forward
  • Safety:
    • Functions called by multiple threads must be "thread safe"
    • A defect in one thread can damage all of the threads in a process (since they share the same address space and other attributes)
  • Resources:
    • Threads share the resources (e.g., address space) of a single process
  • Signals:
    • Are very hard to use in multi-threaded programs
Advantage or Disadvantage?
Back SMYC Forward
  • Text/Code Segment:
    • All threads must run the same program
    • Different processes can run different programs
  • Shared Information:
    • Threads share file descriptors, the working directory, and various IDs
    • Processes "inherit" file descriptors, can have a different working directory, and have different IDs
There's Always More to Learn
Back -