What is the use of thread over process?

Answer Posted / sandeep patra

Thread is an executable entity but it is bound to its parent
process.
now there are two types of threads.
1. user space threads and
2. kernel thread
now the kernel threads are actually known as light weight
processes.

why light weight????
>>>> as it's context switching times is lesser than all
other process.

now why the context switching time is less????
>>>>> as process have there own process address space and
maintains many more things like userID, ProcessID, groupID,
number of files opened, reisters and blah, blah
whereas thread shares it's parent process's address space
and mainly contains three things like own stack, registers
and thread related data.
so more things to swap need more time that's why thread's
context switching time is less compared to that of a process.

now the answer,
use of thread: thread are used to provide multi-programming
environment.
ok, now u ppl would think that, it can also be done creating
new processes (using fork())
yes we can,
but as i told earlier that the context switch time for
threads are very less.
moreover the inter-thread communication is more easier than
inter-process communication as all threads of a single
process uses the same address space.

Is This Answer Correct ?    61 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are threads and processes?

476


What do cores and threads mean?

432


Does thread count matter cpu?

431


What is pthread in linux?

448


How many threads can one core handle?

441






How many goroutines are in a thread?

448


What do cores and threads do?

447


Do threads share registers?

445


is there a command line shortcut to the login directory

1224


Is thread an abstract class?

436


Which thread method is called when a thread starts?

426


Does linux have threads?

433


Do threads count as cores?

419


Is creating a thread expensive?

441


How many cores and threads do I need?

430