绿色线程的缺点:宿主内核线程块

Downside of green threads: host kernel thread blocks

我目前正在学习操作系统,我对Implementing Multi-Threaded Processes的某些部分理解有困难。

具体来说,课本上说明了我们可以通过名为Per-Processor Kernel Threads的系统实现用户级线程。关于本系统的详细说明如下:

When the application starts up, the user-level thread library creates one kernel thread for each processor on the host machine. As long as there is no other activity on the system, the kernel will assign each of these threads a processor. Each kernel thread executes the user-level scheduler in parallel: pull the next thread off the user-level ready list, and run it. Because thread scheduling decisions occur at user level, they can be flexible and application specific.

但是,接下来,它也提到了这个系统有一些缺点,类似于绿色线程。下面提到的一些缺点

  • Any time a user-level thread calls into the kernel, its host kernel thread blocks. This prevents the thread library from running a different user-level thread on that processor in the meantime.

  • Any time the kernel time-slices a kernel thread, the user-level thread it was running is also suspended. Thi library cannot resume that thread until the kernel thread resumes.

我不能完全理解他们两个。 这是我的问题。

  1. 如果用户级线程调用内核,为什么宿主内核线程会在这个系统中阻塞?
  2. kernel time-slices a kernel thread 是什么意思?
  3. 如果内核时间片内核线程,为什么用户级线程运行被挂起?

谢谢。

您所描述的有时在教科书中被称为多对多模型,并增加了内核线程数受限于处理器数量的限制。

我不知道有任何操作系统以这种方式实现线程。 (如果有人知道一些非学术操作系统以这种方式进行线程处理,请赐教。)这样的系统实现起来会非常复杂。

用户线程没有任何真正的优势。可悲的是,大多数操作系统教科书最好使用猫盒衬垫。许多人坚持描述用户线程在理论上(但不切实际)的优势,而这些优势在现实世界中根本不存在。所描述的是内核线程之上的 运行 用户线程。

这种说法简直让人发笑:

Because thread scheduling decisions occur at user level, they can be flexible and application specific.

a) 您仍将[隐含地]在底层使用不灵活的内核线程。

b) 如果可以通过这种方式使用用户线程获得更好的性能,那么操作系统对内核线程的实现必须是完全无能的。

这是总分:

Any time a user-level thread calls into the kernel, its host kernel thread blocks. This prevents the thread library from running a different user-level thread on that processor in the meantime.

a) 存在非阻塞内核调用。

b) 在某些逆行操作系统中调用 I/O 系统服务会阻塞用户线程。并非所有操作系统都如此。

针对您的具体问题:

If a user-level thread calls into the kernel, why host kernel thread blocks in this system?

见上文。它只发生在一些设计不佳的操作系统中的某些系统调用。

What does kernel time-slices a kernel thread mean?

是的,那是糟糕的英语。在线程调度中,进程可能会被给予固定的时间量("time slice" 或 "quantum"),它可以在调度程序开始查看是否应该轮到另一个线程执行之前执行。如果您有一个线程在不执行 I/O 的情况下进行长时间计算,则此时间限制可防止该线程占用系统。

为什么这是这个线程模型的特定缺点我不明白。同样的事情发生在纯内核线程中。或者纯用户线程。

遗憾的是,您所看到的是一本将简单概念变得过于复杂的书。你有我的同情。