本文介绍了调度用户级线程在可用的 LWP 上运行到底是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道将线程安排在 LWP 上运行究竟意味着什么.我无法正确地可视化当一个进程被安排在 CPU 上运行时发生的步骤序列,因为在高级视图中解释了很多概念.下面是导致很多人挠头的段落;它来自 Abraham Silberschatz操作系统概念,第 10 版.

I want to know what exactly it means for a thread to be scheduled to run on an LWP. I'm unable to properly visualise the sequence of steps that happen when a process is scheduled to run onto the CPU because a lot of concepts are explained in a high level view. Below is the paragraph that resulted in a lot of head scratching; it is from Operating System Concepts, 10th Edition by Abraham Silberschatz.

用户级线程和内核级线程之间的一个区别在于它们如何被安排.关于实现多对一的系统(第 4.3.1 节)和多对多(第 4.3.3 节)模型,线程库调度用户-在可用的 LWP 上运行的级别线程.这种方案被称为过程-争用范围 (PCS),因为 CPU 的竞争发生在属于同一进程的线程.(当我们说线程库将用户线程调度到可用的 LWP 上时,并不是说线程是实际上运行在 CPU 上,因为这进一步要求操作系统将 LWP 的内核线程调度到物理 CPU 内核上.)

我无法完全理解 LWP 在这里的必要性和重要性.

I'm unable to fully comprehend the need and significance of LWP's here.

推荐答案

就像进程是内存的容器一样,LWP(= 内核级线程)也是纤程(= 用户级线程,本质上)的容器.

Just like a process is a container for memory, the LWP (= kernel-level thread) is a container for fibers (= user-level threads, essentially).

内核的线程调度程序只看到内核级线程 (LWP),它在 CPU 上和下调度 LWP——也就是说,LWP 有一个时间片,它可以在 CPU 上运行.用户级线程库(=纤程调度程序)拥有该进程的 LWP,它决定哪些纤程可以使用内核调度程序分配给这些 LWP 的时间片.

The kernel's thread scheduler only sees kernel-level threads (LWPs), and it schedules LWPs on and off the CPUs - namely, an LWP has a time slice where it gets to run on a CPU. The user-level thread library (= fiber scheduler) owns the LWPs of that process, and it decides which fibers get to use the timeslices allocated by the kernel's scheduler to those LWPs.

当纤程决定让出 CPU,但 LWP 的时间片尚未结束时,纤程调度程序会调度另一纤程在该 CPU 上的 LWP 内运行.但是,当其他光纤正在运行时,LWP 的时间片可能会用完,内核的调度程序会将该 LWP 调度到 CPU 之外.光纤调度程序不会对此事发表意见 - 光纤调度程序甚至无法运行,因为它在用户空间中,而内核不知道这一点.

When a fiber decides to yield the CPU, but the LWP's timeslice is not over yet, the fiber scheduler schedules another fiber to run within the LWP on that CPU. But while that other fiber is running, the LWP's timeslice might run out, and the kernel's scheduler will schedule that LWP off the CPU. The fiber scheduler will not have a say on the matter - the fiber scheduler won't even get to run, because it's in userspace and the kernel is not aware of it.

这篇关于调度用户级线程在可用的 LWP 上运行到底是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 23:04