After reading difference between user-level threads and kernel-level threads ,now I am in doubt of context switching.Context switching is managed by OS when switching between processes/threads but google didn't clarify me when i asked it that in which case more number of switching will take place for these cases :

1). User-level thread switched to another user-level

2).kernel-level thread switched to another kernel-level

3). User-level thread switched to kernel-level

Anyone please make it clear

  • $\begingroup$ This doesn't really sound like computer science to me, but I'm just a new user here myself. $\endgroup$
    – dfeuer
    Dec 15, 2014 at 18:09
  • 1
    $\begingroup$ Operating Systems is a part of Computer science curriculum $\endgroup$
    – tonny
    Dec 16, 2014 at 5:06

2 Answers 2


Exceptional Control Flow

There is a process called exceptional control flow to deal with the problem of switching between kernel code and user code. Switching between user mode programs actually need the kernel code being executed between.

Context Switching

When a user mode program times out, an external timer triggers an interrupt. Then the operating system kernel takes back the control, save all registers used by the program. Then schedule another program to run.

Exceptions and Interrupts

There are some kinds of exceptional interrupts from outside, for instance user hit Ctrl-C or when you try to open a file (syscall), it will switch to kernel code. When the file is opened for you, the program will come back running. Another example is on modern virtual memory systems, if a memory requested is currently in a disk, not on memory, the system will interrupt the program by a page fault. Then the computer continue to run kernel code to fetch that portion of memory and come back to the program.


User level threads is usually meant to be threads managed in userspace. The context switching is done in userspace, by the threading library. There is just one (kernel level) thread running at a time in the application, even if there are several processors.

Kernel level threads, in contrast, means that the kernel is aware of the threads in the application, Context switching is in the kernel, more than ore thread can be active at the same time.

In the Linux case, some experiments where done a long while back, to measure performance of both models (and a hybrid model, combining both). Pure kernel threads won hands down.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.