2

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?

SSP
  • 2,650
  • 5
  • 31
  • 49
K.Ray
  • 21
  • 2
  • 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 Oct 13 '19 at 23:04
  • 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 Oct 15 '19 at 03:35

1 Answers1

1

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

Xiao-Feng Li
  • 680
  • 7
  • 12
  • Thank you very straightforward to explain, let me clear up a lot of concepts. I feel that I need to strengthen my knowledge of user thread mapping kernel thread. – K.Ray Oct 16 '19 at 11:04