- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在看用户级线程和内核级线程之间的区别,我基本了解。
我不清楚的是实现用户级线程的意义。
如果内核不知道单个进程中存在多个线程,那么我可以体验到哪些好处?
我已经阅读了几篇文章,指出只有在此类线程不执行阻塞操作(这会导致整个进程阻塞)时,才建议使用线程的用户级实现。
话虽如此,考虑到它们不能利用多个处理器和独立调度,所有线程的顺序执行和它们的“并行”执行之间有什么区别?
对先前提出的问题(类似于我的)的回答类似于:
No modern operating system actually maps
n
user-level threads to1
kernel-level thread.
最佳答案
我强烈推荐Modern Operating Systems 4th Edition由 Andrew S. Tanenbaum (主演 debate about Linux 等节目;也参与:Linus Torvalds )。花费一大笔钱,但如果你真的想知道一些东西,这绝对是值得的。对于热心的学生和绝望的爱好者来说,这很棒。
你的问题得到解答
[...] what's not clear to me is the point of implementing User-level threads at all.
If the kernel is unaware of the existence of multiple threads within a single process, then which benefits could I experience?
I have read a couple of articles that stated that user-level implementation of threads is advisable only if such threads do not perform blocking operations (which would cause the entire process to block).
The first, and most obvious, advantage is that a user-level threads package can be implemented on an operating system that does not support threads. All operating systems used to fall into this category, and even now some still do.
When a thread does something that may cause it to become blocked locally, for example, waiting for another thread in its process to complete some work, it calls a run-time system procedure. This procedure checks to see if the thread must be put into blocked state. If, so it stores the thread’s registers (i.e., its own) [...] and reloads the machine registers with the new thread’s saved values. As soon as the stack pointer and program counter have been switched, the new thread comes to life again automatically. If the machine happens to have an instruction to store all the registers and another one to load them all, the entire thread switch can be done in just a handful of in- structions. Doing thread switching like this is at least an order of magnitude—maybe more—faster than trapping to the kernel and is a strong argument in favor of user-level threads packages.
They [user-level threads] allow each process to have its own customized scheduling algorithm. For some applications, for example, those with a garbage-collector thread, not having to worry about a thread being stopped at an inconvenient moment is a plus. They also scale better, since kernel threads invariably require some table space and stack space in the kernel, which can be a problem if there are a very large number of threads.
read
系统调用。 OTOH,一个内核级的调度算法会知道,因为它可以通过系统调用得到通知;两者都属于内核代码库。
Suppose that a thread reads from the keyboard before any keys have been hit. Letting the thread actually make the system call is unacceptable, since this will stop all the threads. One of the main goals of having threads in the first place was to allow each one to use blocking calls, but to prevent one blocked thread from affecting the others. With blocking system calls, it is hard to see how this goal can be achieved readily.
select
预测系统校准何时阻塞。但他说这很不雅。
For applications that are essentially entirely CPU bound and rarely block, what is the point of having threads at all? No one would seriously propose computing the first
n
prime numbers or playing chess using threads because there is nothing to be gained by doing it that way.
Somewhat analogous to the problem of blocking system calls is the problem of page faults. [...] If the program calls or jumps to an instruction that is not in memory, a page fault occurs and the operating system will go and get the missing instruction (and its neighbors) from disk. [...] The process is blocked while the necessary instruction is being located and read in. If a thread causes a page fault, the kernel, unaware of even the existence of threads, naturally blocks the entire process until the disk I/O is complete, even though other threads might be runnable.
[...] if a thread starts running, no other thread in that process will ever run unless the first thread voluntarily gives up the CPU. Within a single process, there are no clock interrupts, making it impossible to schedule processes round-robin fashion (taking turns). Unless a thread enters the run-time system of its own free will, the scheduler will never get a chance.
[...] to have the run-time system request a clock signal (interrupt) once a second to give it control, but this, too, is crude and messy to program.
关于multithreading - 用户级线程的好处,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34569354/
如果函数定义顺序不对,Jslint 将指出错误。 显然 jslint 是严格的,但我想知道将函数按顺序排列是否有任何好处。 我的意思是在调用它们之前定义它们。 最佳答案 函数定义(和 var 语句)被
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 8 年前。 Improve this ques
我注意到Flask tutorial涉及到点的使用。看起来它只是用于在本地创建一个轮子,这将使服务器上的设置变得更容易,但作为一个网络开发新手,我很好奇:是否有人真的会一路将他们的网站上传到像 PyP
我一直在阅读有关 jquery live event 的内容,但仍然有点困惑?使用它有什么好处? http://docs.jquery.com/Events/live 我知道它与绑定(bind)类似,
这是我的故事:我已将我的应用迁移到 AndroidX,因为我需要从网上找到的库中获取一些新功能。 问题:我目前遇到了一些问题,因为我现在需要为 Cordova 开发一个插件来实现该应用程序的一部分。
在使用 RAD 或一般不使用单元测试时使用依赖注入(inject)是否有任何好处? 最佳答案 是的,有以下几个好处: 减少依赖 减少依赖携带 更多可重用代码 更多可测试代码 更具可读性的代码 更多引用
我目前正在构建一个通过 MSI Windows Installer 分发的产品。我们的客户正在使用不同的形式(例如我们在他们自己的 MSI 中)集成该产品,使用 Bootstrap /链接器(如 Wi
有人声称 Scala 的类型系统是图灵完备的。我的问题是: 这有正式的证据吗? 简单的计算在 Scala 类型系统中会是什么样子? 这对 Scala 这种语言有什么好处吗?与没有图灵完备类型系统的语言
我开始尝试使用 React,我注意到我正在制作的简单应用程序全部使用 JS。我的 html 页面只是一个空的 body 标签! 所以我有几个问题,因为我是这个框架的新手。 我的整个应用程序应该基本上都
我们有一个相当大的基于 Windows 的 1.1 .NET 应用程序,我们正在考虑升级到 2.0。我们考虑更新的主要原因是我们可以利用 Visual Studio 2008 进行项目的持续开发,以及
我有一个页面,其中内置了基于 ajax 的分页。分页用于页面中的“评论”功能。根据 Google 的网站管理员博客,具有 rel="next"和 rel="prev"值有利于 SEO。 我在头部添加了
我是一名优秀的程序员,十分优秀!