1,886 views
1 votes
1 votes
Consider the following statements given below:

S1: User-level threads switching does not require context switching.

S2: Virtual memory increases the context switching overhead.

S3: Every thread has its own registers and stack but not program counter.

which of the following is or are correct?

What I know: Context switching is faster in user level threads than kernel level threads,

Then how come S1 is true?

1 Answer

3 votes
3 votes

User Level Thread Switching and User Level Context Switching are different conceptually when we talk about User level Thread.

1)USER LEVEL THREAD SWITCHING( or USER LEVEL CONTEXT SWITCHING IN USER MODE)

Initially, User Level Threads perform Thread Switching (when blocking operation is performed explicitly in user level address space by PROCEDURE CALLS or LIBRARY CALLS instead of SYSTEM CALLS) with the help of Thread Libraries without any involvement of Kernel and so the entire operation is very fast.

This is basically referred to as User Mode where User Level Thread Switching takes place and Thread Switching Concept is applicable for User Level Thread Only. Whereas, term Context Switching (discussed later) is applicable to BOTH User Level and Kernel Level Threads which is actually Kernel Mode.

GATE Question Type Prediction

This User Mode or User Level Thread Switching is sometimes referred to as User Level Context Switching (mistakenly/debatable)  when the question comes in GATE as  wheather user level context switching faster than Kernel level Context Switching or not.

The answer will be YES since here actually User Level Thread Switching is referred to here as User Level Context Switching in User Mode and so obviously User Level Thread Switching is faster than Kernel Level Context Switching 

2) But later on, we see actually  Context Switching for Both User Level and Kernel Level Threads occurs only in Kernel Mode i.e., with the involvement/intervention of Kernel in Kernel level address spaces and that too by Using Blocking System Calls only(NOT PROCEDURE or LIBRARY SYSTEM CALLS)

Here,when involvement of Kernel comes into picture(mostly during process preemption or interrupt),it is called Kernel mode Context Switching which becomes much slower than User Level Thread Switching (or so called User Level Context Switching in User Mode) Because User Level Context Switching in User Mode or Thread Switching(to be more specific) uses PROCEDURE or LIBRARY CALLS(together sometimes called as non blocking system calls) which are quite fast compared to SYSTEM CALLS (blocking system calls)used in Kernel Mode.

Thus,User Level Thread Switching does not mandatorily require Context Switching ie involvement of Kernel when blocking operation is performed in user level address space.

Here,instead of Kernel Scheduler,

New Thread creation,Thread Scheduling and Synchronisation is handled by Thread Scheduler, also called ULS(User Level Scheduler) along with User Level Stack associated with each User Level Thread.

Related questions