Threads vs Processes

Rukshani Athapathu
Coder's Corner
Published in
2 min readOct 22, 2017

Just a brief note to highlight the main difference between a thread and a process.

A Process

A process is an independently running instance of a program. If you open a same program multiple times, multiple processes will be utilized. These processes in an operating system share system resources such as memory and CPUs (processors) and when one program is waiting for some operation, another can utilize the resources.

A Thread

Within a process, you can have multiple threads simultaneously running your program flow. Even though each thread has it’s own stack and local variables, they do share the memory address space of their owning process. Because of that, threads that are in the same process share the objects allocated to it in the heap and will cause the program to behave unpredictably if access to the shared data is not coordinated properly with the use of synchronization.

A program with one thread in a multi processor system

Will run on only one processor at a time.

If the system has two processors this program will give up access to half of it’s available CPU resources. If the system has 100 processors, it will give up 99% of access to CPU resources (Brian Goetz et al, 2006).

A program with multiple threads in a multi processor system

Can run simultaneously on multiple processors and if one thread waits for some operation, another thread can run which makes this better than having a single threaded program, where the processor sits idle while waiting for some operation to complete (Brian Goetz et al, 2006).

References

--

--