用户级线程 (ULT) 和内核级线程 (KLT) 在并发执行方面有何不同? [英] How do user level threads (ULTs) and kernel level threads (KLTs) differ with regards to concurrent execution?

查看:19
本文介绍了用户级线程 (ULT) 和内核级线程 (KLT) 在并发执行方面有何不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的理解;请更正/添加:

Here's what I understand; please correct/add to it:

在纯 ULT 中,多线程进程本身进行线程调度.因此,内核本质上没有注意到差异并将其视为单线程进程.如果一个线程进行阻塞系统调用,则整个进程都会被阻塞.即使在多核处理器上,除非进程被阻塞,否则一次只能运行进程的一个线程.不过我不确定 ULT 有多大帮助.

In pure ULTs, the multithreaded process itself does the thread scheduling. So, the kernel essentially does not notice the difference and considers it a single-thread process. If one thread makes a blocking system call, the entire process is blocked. Even on a multicore processor, only one thread of the process would running at a time, unless the process is blocked. I'm not sure how ULTs are much help though.

在纯 KLT 中,即使一个线程被阻塞,内核也会调度同一进程的另一个(就绪)线程.(在纯 KLT 的情况下,我假设内核创建了进程的所有线程.)

In pure KLTs, even if a thread is blocked, the kernel schedules another (ready) thread of the same process. (In case of pure KLTs, I'm assuming the kernel creates all the threads of the process.)

此外,使用 ULT 和 KLT 的组合,如何将 ULT 映射到 KLT?

Also, using a combination of ULTs and KLTs, how are ULTs mapped into KLTs?

推荐答案

你的分析是正确的.操作系统内核不知道用户级线程.从它的角度来看,进程是一个不透明的黑盒子,偶尔会进行系统调用.因此,如果该程序有 100,000 个用户级线程但只有一个内核线程,那么该进程一次只能运行一个用户级线程,因为只有一个内核级线程与之关联.另一方面,如果一个进程有多个内核级线程,那么如果有一个多核机器,它就可以并行执行多个命令.

Your analysis is correct. The OS kernel has no knowledge of user-level threads. From its perspective, a process is an opaque black box that occasionally makes system calls. Consequently, if that program has 100,000 user-level threads but only one kernel thread, then the process can only one run user-level thread at a time because there is only one kernel-level thread associated with it. On the other hand, if a process has multiple kernel-level threads, then it can execute multiple commands in parallel if there is a multicore machine.

它们之间的一个常见折衷是让程序请求一些固定数量的内核级线程,然后让自己的线程调度程序根据需要将用户级线程分配到这些内核级线程上.这样,多个 ULT 可以并行执行,并且程序可以对线程的执行方式进行细粒度控制.

A common compromise between these is to have a program request some fixed number of kernel-level threads, then have its own thread scheduler divvy up the user-level threads onto these kernel-level threads as appropriate. That way, multiple ULTs can execute in parallel, and the program can have fine-grained control over how threads execute.

至于这种映射是如何工作的 - 有很多不同的方案.您可以想象用户程序使用多个不同调度系统中的任何一个.事实上,如果你做这个替换:

As for how this mapping works - there are a bunch of different schemes. You could imagine that the user program uses any one of multiple different scheduling systems. In fact, if you do this substitution:

内核线程 <---> 处理器内核

Kernel thread <---> Processor core

用户线程<--->内核线程

User thread <---> Kernel thread

那么操作系统可以用来将内核线程映射到内核的任何方案也可以用来将用户级线程映射到内核级线程.

Then any scheme the OS could use to map kernel threads onto cores could also be used to map user-level threads onto kernel-level threads.

希望这有帮助!

这篇关于用户级线程 (ULT) 和内核级线程 (KLT) 在并发执行方面有何不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆