2,871 views
8 votes
8 votes
S1: Context Switching occurs only in kernel mode. :TRUE

S2: Context Switching in user mode is faster as compared to context switching in kernel mode. : TRUE

If Context Switching occurs only in kernel mode, then how is CS in user mode faster as compared to that in kernel mode?

According to me, for CS to occur in user mode, it should first change to kernel mode, perform context switching and then change back to user mode which means more time should be taken as compared to CS in kernel mode.

3 Answers

1 votes
1 votes

Here meaning of context switch is a bit different for user level threads . As OS is just unaware  of the threads so OS is  not involved in scheduling of these threads , thus kernel is not required for thread switching purpose . All these functionalities of threads is managed by a thread library which is used to create and manage these user level threads . Hence thread Switching(User level context switching) is faster. Reference http://lass.cs.umass.edu/~shenoy/courses/fall12/lectures/notes/Lec06_notes.pdf

0 votes
0 votes
I think you are missing a major point here.
S1 and S2 are true, but context switching in both S1 and S2 means completely different sets of operations.

Context Switching between kernel level threads needs to be executed in kernel mode which involved saving the state clearing the registers and resetting PC and all. But context switch between user level threads is done in the user mode which does not involve actual PC,register reset . they are simulated variables here. So it is much faster. Actually, I think it is not right to call switching of threads in user mode as “context switching”. These user level threads are simulated threads by use of libraries like pthreads, which will take care of the scheduling too. these will libraries will simulate the multi threaded scenario to the user. But in the ground level only one kernel thread will be physically running in a core mostly(but more than many to many mappings can also be done between user level threads and kernal level threads to achieve true concurrency).
0 votes
0 votes

Here is a difference between user and kernal mode which given the proper view of this question.

Related questions

1 votes
1 votes
0 answers
1
anisha007 asked Sep 25, 2018
721 views
What is the least number of context switching required for 'n' number of processes?
0 votes
0 votes
0 answers
3
srestha asked May 19, 2019
621 views
User level threads doesnot require context switching- This is a true statement (Because OS cannot recognize user level threads)Can somebody elaborate more on it??This giv...
0 votes
0 votes
0 answers
4