Does the thread supported by the kernel run in the kernel state?

Viewed 79

I'm a little confused about kernel space, userspace, kernel thread, user thread. Whether you can think that kernel threads are supported by the kernel is running in kernel space?

Java,

`Thread t = new Thread(new Runnable...)`,

This thread named 't' is called a lightweight process (kernel thread) in Linux. Is it running in the kernel state?

1 Answers

Need some fundamental OS concepts clarification:

  • Kernel thread is a thread entity that is managed and scheduled by OS kernel directly. User level program can access kernel thread through system calls such as via pthread APIs. If a user program binds its code execution with a kernel thread, it is then a user thread that is mapped to a kernel thread.
  • Light-weight process is not a well-defined term, but it usually refers to a kernel thread that is exposed to user space, in contrast to normal process which is heavier than a thread. In this sense, you can consider kernel thread is the same as light-weight process.
  • Java thread is a user thread entity that is normally supported by a kernel thread (or you can call it a light-weight process). That means, the execution of a Java thread can be scheduled directly by the OS kernel.

So you are correct that a Java thread is mapped to a kernel thread, but Java thread does not run in kernel space. It is scheduled by the OS kernel directly, and surely has kernel thread data in kernel space. And sometimes a user thread may run in kernel space, when it invokes system call...

Related