简体   繁体   English

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

[英]Downside of green threads: host kernel thread blocks

I am currently studying operating system and I have difficulties understanding some parts about Implementing Multi-Threaded Processes . 我目前正在研究操作系统,并且难以理解有关Implementing Multi-Threaded Processes某些部分。

To be specific, the textbook explains that we can implement user-level threads by the system called Per-Processor Kernel Threads . 具体来说,教科书解释说,我们可以通过称为“ Per-Processor Kernel Threads的系统来实现用户级线程。 The detailed explanation about this system is below: 有关此系统的详细说明如下:

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. 由于线程调度决策发生在用户级别,因此它们可以是灵活的且针对特定应用程序。

However, next, it also mentions there are some downsides of this system, which is similar to that of green threads. 但是,接下来,它还提到了该系统的一些缺点,类似于绿色线程。 Some downsides mentioned are below 下面提到的一些缺点

  • 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. 在内核线程恢复之前,Thi库无法恢复该线程。

I cannot totally understand both of them. 我不能完全理解他们两个。 Here are my questions. 这是我的问题。

  1. If a user-level thread calls into the kernel, why host kernel thread blocks in this system? 如果用户级线程调用内核,为什么在该系统中宿主内核线程块?
  2. What does kernel time-slices a kernel thread mean? kernel time-slices a kernel thread是什么意思?
  3. If kernel time-slices a kernel thread, why user-level thread running is suspended? 如果内核对内核线程进行时间切片,为什么要暂停用户级线程的运行?

Thanks. 谢谢。

What you are describing is sometimes referred to as the many-to-many model in textbooks with the added constraint that the number of kernel threads are limited to the number of processors. 您所描述的内容有时在教科书中称为“多对多模型”,但增加了约束,即内核线程数限制为处理器数。

I do not know of ANY operating system that implements threads this way. 我不知道任何以这种方式实现线程的操作系统。 (If someone out there know of some non-academic Operating system that does threading this way, please enlighten me.) Such a system would be ridiculously convoluted to implement. (如果有人知道一些非学术性操作系统以这种方式进行线程化,请启发我。)这样的系统将被难以理解地实现。

There is no real advantage whatsoever to user threads. 用户线程没有任何真正的优势。 Sadly, most Operating Systems textbooks are best used a cat box liner. 可悲的是,大多数操作系统教科书最好使用猫盒衬板。 Many insist on describing theoretical (but impracticable) advantages of user threads that simply do not exist in the real world. 许多人坚持描述用户线程的理论(但不可行)优势,而这些优势在现实世界中根本不存在。 What is being described is running user threads on top of kernel threads. 描述的是在内核线程之上运行用户线程。

This statement is just laughable: 这句话可笑:

Because thread scheduling decisions occur at user level, they can be flexible and application specific. 由于线程调度决策发生在用户级别,因此它们可以是灵活的且针对特定应用程序。

a) You are still going to have the [implicitly] inflexible kernel thread underneath. a)您仍将在下面具有[隐式]不灵活的内核线程。

b) The operating system's implementation of kernel threads would have to be completely inept if one could get better performance with user threads in this manner. b)如果可以通过这种方式使用户线程获得更好的性能,则操作系统的内核线程实现将必须完全无效。

This is total BS: 这是总BS:

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) There are non-blocking kernel calls. a)有非阻塞内核调用。

b) Calling I/O system services in SOME retrograde operating systems blocks user threads. b)在某些逆行操作系统中调用I / O系统服务会阻塞用户线程。 This is not true in all operating systems. 并非在所有操作系统中都是如此。

To your specific questions: 对您的具体问题:

If a user-level thread calls into the kernel, why host kernel thread blocks in this system? 如果用户级线程调用内核,为什么在该系统中宿主内核线程块?

See above. 往上看。 It only happens for some system calls in some poorly designed operating systems. 它仅在某些设计欠佳的操作系统中的某些系统调用中发生。

What does kernel time-slices a kernel thread mean? 内核时间切片内核线程是什么意思?

Yes, that's poor English. 是的,那是糟糕的英语。 In thread scheduling a process is may be given a fixed amount of time ("time slice" or "quantum") that it can execute before the scheduler kicks in to see if another thread should be given a turn to execute. 在线程调度中,可以给进程一个固定的时间量(“时间片”或“量子”),该时间可以在调度程序启动之前执行,以查看是否应轮流执行另一个线程。 If you have a thread that does long calculations without doing I/O, this time limit prevents that thread from hogging the system. 如果您有一个线程在不执行I / O的情况下进行长时间计算,则此时间限制将阻止该线程占用系统。

Why this is a specific drawback of this thread model is beyond me. 为什么这是此线程模型的特定缺点,这超出了我的范围。 The same thing happens in pure kernel threads. 同样的事情在纯内核线程中也会发生。 Or pure user threads. 或纯用户线程。

Sadly, what you have here is a book that is taking simple concepts and making them overly complicated. 可悲的是,您所拥有的是一本书,其中包含简单的概念并使它们过于复杂。 You have my sympathies. 你有我的同情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM