Difference between Process and a Thread
A Process is in essence, a program that is executing. Thus process-based multi-tasking is the feature that allows your computer to run 2 or more programs concurrently. For example process-based multitasking enables you to run the java compiler and a text editor concurrently.
In process-based multi-tasking, a program is the smallest unit of code that can be dispatched.
In Thread-based multi-tasking, a thread is the smallest unit of code that can be dispatchable code.
For instance, a text editor can format text at the same time that it is printing, as long as these actions are being performed by 2 different threads.
Multitasking threads require less overhead than multitasking processes. Processes are heavyweight tasks that require their own seperate address spaces. Interprocess communication is expensive and limited. Context switching from one process to another is also costly.
Threads on the other hand are lightweight. They share the same address space and cooperately share the same heavyweight process. Interthread communication is inexpensive and context switching from one thread to another is low cost.
Multithreading allows you to write very efficient programs that make maximum use of the CPU, because idle time can be kept minimum.
A Process has its own memory space, runtime environment and process ID.
A Thread run inside a Process and shares its resources with other threads.
0 Comments:
Post a Comment
<< Home