Both threads and processes are methods of parallelizing an application. However, processes are independent execution units that contain their own state information, use their own address spaces, and only interact with each other via interprocess communication mechanisms (generally managed by the operating system).Thread is a design construct that doesn't affect the architecture of an application. A single process can have multiple threads; all threads within a process share the same state and same memory space, and can communicate with each other directly, because they share the same variables.
T1 and T2 are threads inside one process.Process is unit of allocation of resources but the threads are unit of execution.Inter process communication is always expensive. it needs context switch, whereas
inter thread communication is cheap, it can use process memory and may not need to context switch. The process are secure as one process is dead, other process wont get affected, but if one thread get corrupt and die ,other threads and even corresponding process will get die.
"Inter process communication is always expensive. it needs context switch" = When you use IPC mechanism of socket programming, do we have a context switch happening here? I don't think so. Both processes will be running on their corresponding processors seperately and exchange info. Please correct me if I am wrong. I mean to say not all the times IPC will have a context switch.
ReplyDelete