in Operating System
694 views
1 vote
1 vote
Why threads have less context than process?

Context means various attributes that we store in the PCB,so the attributes like state,property,PC,etc..  should be there in both process and thread.So,how thread have less context than process?
in Operating System
694 views

3 Comments

because thread have only copy of PC, stack and general purpose registers, which has to be saved during context switch but unlike process they share both code and data segment, which need not to be saved during context switching, thus leading to less context switch time..

4
4
Paging increases context switch time why ???
0
0
@Joshi nitish, I am also thinking the same as you mentioned. But the code and data also get saved when we do the context switching? The process(P1) is already in the main memory(ready queue),and suppose now it is in running state and the some high priority comes and pre empt,P1,Now we will save the context  of P1 so that we can retrieve it later.So,we should store only the attributes in PCB ,why and where do we save its code and data segment?code and data segmentwill always resides in main memory regardless the process is in ready or runing.
0
0

2 Answers

1 vote
1 vote
Hello, here if u r asking this then first of all u please read galvin by the I m giving u some overview if we consider threds that means we r talking about light weight process which shares some common resources or data structures like stack and registers and some open files in PCB   of process therefore in context switch of threds takes very less time in compare to process context switch.
1 vote
1 vote

In computing, a context switch is the process of storing the state of a process or of a thread, so that it can be restored and execution resumed from the same point later. 

Switching from one process to another requires a certain amount of time for

1) doing the administration - Like Saving and loading registers and memory maps, updating various tables and lists, etc. What is actually involved in a context switch varies between these senses and between processors and operating systems.

NOTE: The scheduler doesn't see any difference between thread/process it sees them all equally as a task/job (In Linux)

2) Context switching involves switching registers, stack pointer, and program counter (PC) , (In threads these are the only things that'll be switched. And NOT the Address space!

3) Though in a process switch ( i.e context switch of a process) an address space switch also happens

4) Finally, Context switching itself has a cost in performance, due to running the task schedulerTLB flushes, and indirectly due to sharing the CPU cache between multiple tasks. 

5) However Switching between threads of a single process can be faster than between two separate processes, because threads share the same virtual memory maps, so a TLB flush is not necessary.

Related questions