Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 8 down vote accepted

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.

share|improve this answer
    
what is the implementation like on Linux? –  yati sagade Sep 14 '11 at 9:57
1  
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. –  David Schwartz Sep 14 '11 at 10:02
    
thanks a ton :) –  yati sagade Sep 14 '11 at 10:09
    
"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? –  Dark Templar Sep 17 '11 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. –  David Schwartz Sep 18 '11 at 1:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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