Multithreading – Kernel Threads vs. User-Level Threads Explained

multithreading

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?

Best Answer

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.

Related Topic