Monday, December 05, 2005

Difference between Threads and Process

From the book Parallel and Distributed Programming Using C++ BY Tracey Hughes,
Cameron Hughes , Published by Addisioin-Wesley.


LINK:
{
http://books.google.com/books?ie=UTF-
8&hl=en&id=RQT5XeqaagEC&dq=Difference+between
+Thread+and+Process&prev=http://books.google.com/
books%3Fq%3DDifference%2Bbetween%2BThread%2Band%2BProcess&lpg
=PA102&pg=PA104&sig=
7XWb4nEO4BnjVFz1uGSAdwseDJs}



The major difference between Threads and Processes is each process has its own
address space and thread don't. If a process creates multiple threads, all the threads will be contained in its address space. This is why they share resources so easily and interthread communication is so simple. Child processes have their own address space and a copy of the data segment. Therefore, when a child changes its variables or data, it does not affect the data of its parent process. A shared memory area has to be created in order for parent and child processes to share data. Interprocess communication mechanisms, scuh as pipes and fifos, are used to communicate or pass data between them. Threads of the same process can pass data and communication by reading and writing directly to any data that is accesible to the parent process.

Similarites between Threads and Processes


  • Both has an id, set of registers, state, priority and scheduling policy.
  • Both have attributes that describe the entity to the OS.
  • Both have an information block.
  • Both share resources with the parent process.
  • Both function as independent entities from the parent process.
  • The creator cna exercise some control over the thread or process.
  • Both can change their attributes.
  • Both can create new resources.
  • Neither can access the resources of another process.

Differences Between Threads and Processes

  • Threads share the address space of the process that created it; processes have their own address.
  • Threads have direct access to the data segment of its process; processes have their own copy of the data segment of the parent process.
  • Threads can directly communicated with other threads of its process; processes muse use interprocess communication to communicate with sibling processes.
  • Thread have almost no overload; processes have considerable overhead.
  • New threads are easily created; new processes require duplication of the parent process.
  • Threads can exercise considerable control over threads of the same process; processes can only exercise control over child processes.
  • Changes to the main thread (cancellation, prority change, etc.) may affect the behavior of the other threads of the process; changes to the parent process does not affect childe processes.


No comments: