Classification of thread

  • ULT: A thread created in user space. For example, a player process creates multiple user threads in user space. These threads can be created, destroyed, and communicated without the need for scheduling. These threads can not call the operating system directly, the scheduler needs to allocate a kernel thread, the user thread and the kernel thread have a mapping relationship, and then call the system through this kernel thread.
  • Kernel-level threads (KLT) : Ring0 level

Because of thread safety, only threads in kernel space can call the operating system.

The kernel doesn’t know anything about the user’s thread packages, so the kernel perspective is to manage them in the normal way, that is, single-threaded processes (there are run-time systems)

ULT was Java before 1.2, KLT was Java after 1.2

  • There is a 1:1 mapping between user threads and kernel threads in Java threads

Advantages and disadvantages of user threads

With kernel threads being many-to-one, n->1

Advantages:

  • It can be implemented on operating systems that do not support threading
  • Thread management, such as creation and destruction and switching, is much less costly than kernel threads because thread-state procedures and callers are local procedures
  • Allow each process to develop its own scheduling algorithm, thread management is more flexible. You have to write your own hypervisor, different from the kernel
  • Threads can utilize more table space and stack space than kernel-level threads
  • No traps, no context switches, and no flushing of the memory cache, making thread calls very fast
  • Thread scheduling does not require the direct involvement of the kernel and is easy to control

disadvantages

  • When a thread has an IO block, if the blocking system is called, because the kernel is unaware of the existence of multithreading (as mentioned above, the kernel is unaware of the user thread, in a single-threaded manner), thus blocking the entire process (for example, a program process has T1, T2, T3… Multiple threads, when T1 is scheduled and blocked by the kernel thread, where will it always block, causing the whole process to block, other threads in the user process will not switch, blocking all threads), so only one thread can be running in the same process at the same time
  • Page failures can cause similar problems

In user-level threads, the thread table in each process is managed by the runtime system. When a thread transitions to a ready or blocked state, the thread table stores the information needed to restart the thread exactly as the kernel stores information about the process in the process table

A kernel thread

Kernel-level threads are implemented in such a way that each user thread is directly associated with a kernel thread

  • Kernel threads are created and destroyed by the operating system through system scheduling
  • All the work of thread management is done by the kernel

Kernel threads reside in kernel space and are kernel objects. With kernel threads, each user thread is mapped or bound to a kernel thread. The user thread is bound to the kernel thread for its lifetime. Once the user thread terminates, both threads leave the system. This is called one-to-one thread mapping

  • Threads can compete for resources throughout the system

Characteristics of kernel threads

When a thread wants to create a new thread or destroy an existing thread, it makes a system callCopy the code

advantages

- in the multiprocessor systems, the kernel can be executed in parallel in the process of the multiple threads within the same process - if a thread is blocked, switch to other threads in the same process continues to execute (user thread defects) - all calls to block the thread implementation - in the form of system calls when a thread is blocked, The kernel selects threads that can run another process, whereas in user-space implementations, the runtime system always runs threads in its own process - signals are sent to the process, not the thread, and when a signal arrives, which county should handle it? Threads can "register" signals they are interested inCopy the code

I have a lot of knowledge is in the learning process, the article is also a superficial understanding of the learning process, if there are cognitive errors, or we have more to add, I hope to comment in the comment area, I will correct in time, but also can avoid misleading behavior. If you have any learning materials or communication groups, I would like to have a private chat with you, eager to communicate with you, learn together, and make progress together