2
votes

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
No. It is part of the user process running the JVM. The thread named t is a Java object, and it is associated with a user-space thread created by the kernel. t itself is not a lightweight process in Linux, and a lightweight process is not a kernel thread. - user207421
Thank you, can I think that: lightweight process is a kernel-level thread that runs in user space. And I see the Linux documentation saying that Linux uses a lightweight process to implement the posix standard thread. So I said t is a lightweight process in Linux. I mean ‘lightweight process (kernel thread)’ means that the lightweight process is scheduled by the kernel, so it is a kernel-level thread. - K.Ray

1 Answers

1
votes

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...