10

Does anyone know what the difference between these are?

It seems to me that kernel threads correspond to the code that runs the kernel (intuitively), but I'm not sure about the other two...

Also, would the pthreads standard be considered user-level and kernel-supported, since you are accessing a library while the kernel does all the thread scheduling/switching?

1 Answer 1

15

The term "kernel threads" can be used to refer to actual threads that run entirely in kernel space or it can refer to user-space threads scheduled by the kernel. The term "kernel-supported" threads means the latter, threads that run in user-space but are facilitated by the kernel, which usually means the kernel schedules them.

"User-level threads" usually means threads visible to user space. That is, what you create when you call your threading standard's "create thread" function. Generally, the term "user-level thread" is used to mean a thread created by the application code regardless of how it's implemented by the system. It may be a pure user-space thread with little to no kernel support or it may be a thread scheduled by the kernel.

The pthreads standard can be implemented as pure user-space threads (where the kernel schedules the process and the process schedules the threads), kernel-supported threads (where the kernel schedules the threads directly), or a hybrid approach (where the kernel schedules a kernel-level thread which then, in user-space, schedules a user-level thread). The standard doesn't demand any one particular means of implementation. The most common implementation is 1-to-1 mapping where each user-level thread has a corresponding thread that is scheduled by the kernel.

4
  • what is the implementation like on Linux? Commented Sep 14, 2011 at 9:57
  • 3
    On all modern (2.6 kernel or later) Linux systems that I know of, the system's default threading implementation is 1-to-1, each user-level thread has a corresponding KSE (kernel scheduling entity -- basically, a thread scheduled by the Linux kernel). The thread you create with 'pthread_create' will be scheduled directly by the kernel. Modern systems generally use NPTL, older systems used LinuxThreads -- they're both 1-to-1. Commented Sep 14, 2011 at 10:02
  • "or a hybrid approach (where the kernel schedules a kernel-level thread which then, in user-space, schedules a user-level thread)." Hey David,could you explain this again? I'm not sure what is going on... When you say 1-to-1 mapping are you referring to Thread Control Blocks when mentioning kernel-level theads? Commented Sep 17, 2011 at 23:18
  • By 1-to-1 I mean that every time you call 'pthread_create', a new context is created that is scheduled by the kernel. In a hybrid approach, the number of contexts scheduled by the kernel is less than the number of threads created -- the kernel schedules one of those contexts, and then threading library schedules one of the threads created by the application. Commented Sep 18, 2011 at 1:03

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.