The multiprocess vs the multithreading model – pros of the MT model

Here are some pros of the MT model over the single-threaded process:

Context Multiprocess (single-threaded) model Multithreaded (MT) model
Design for parallelized workloads
  • Cumbersome
  • Non-intuitive
  • Using the fork/wait semantics repeatedly (creating a large number of processes) isn't simple or intuitive either
  • Lends itself to building parallelized software; calling the pthread_create(3) in a loop is easy and intuitive as well
  • Achieving a logical separation of tasks becomes easy
  • The OS will have threads take advantage of multicore systems implicitly; for the Linux OS, the granularity of scheduling is a thread, not a process (more on this in the next chapter)
  • Overlapping CPU with IO becomes easy
Creation/ destruction performance Much slower Much faster than processes; resource-sharing guarantees this
Context switching Slow Much faster between the threads of a process
Data sharing Done via IPC (Inter-Process Communication) mechanisms;
involves a learning curve, can be fairly complex; synchronization (via the semaphore) required
Inherent; all global and static data items are implicitly shared between threads of a given process; synchronization (via the mutex) is required
Table 4: Multiprocess versus multithreading model  pros of the MT model

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset