gpt4 book ai didi

linux - 用户线程和内核线程与线程级库和内核级库是否有以下任何一种对应关系?

转载 作者:太空宇宙 更新时间:2023-11-04 05:38:16 29 4
gpt4 key购买 nike

来自Operating System Concepts作者:Abraham Silberschatz、Greg Gagne 和 Peter Baer Galvin,以下是用户线程与内核线程的讨论:

support for threads may be provided either at the user level, for userthreads, or by the kernel, for kernel threads.

  • User threads aresupported above the kernel and are managed without kernel support,

  • kernel threads are supported and managed directly by theoperating system. Virtually all contemporary operatingsystems—including Windows, Linux, Mac OS X, and Solaris— supportkernel threads.

Ultimately, a relationship must exist between user threads and kernelthreads. In this section, we look at three common ways of establishingsuch a relationship: the many-to-one model, the one-to-one model, andthe many-to- many model.

这里是关于创建和管理线程的用户级库与内核级库的讨论:

A thread library provides the programmer with an API for creating andmanaging threads. There are two primary ways of implementing a threadlibrary.

  • The first approach is to provide a library entirely in user space with no kernel support. All code and data structures for the libraryexist in user space. This means that invoking a function in thelibrary results in a local function call in user space and not asystem call.

  • The second approach is to implement a kernel-level library supported directly by the operating system. In this case, code and datastructures for the library exist in kernel space. Invoking a functionin the API for the library typically results in a system call to thekernel.

Three main thread libraries are in use today: POSIX Pthreads, Windows,and Java. Pthreads, the threads extension of the POSIX standard, maybe provided as either a user-level or a kernel-level library. TheWindows thread library is a kernel-level library available on Windowssystems. The Java thread API allows threads to be created and manageddirectly in Java programs. However, because in most instances the JVMis running on top of a host operating system, the Java thread API isgenerally implemented using a thread library available on the hostsystem. This means that on Windows systems, Java threads are typicallyimplemented using the Windows API; UNIX and Linux systems often usePthreads.

用户线程和内核线程是否与线程级库和内核级库有以下几种对应关系?

  • 用户级库是否必须只创建和管理用户线程,而不创建和管理内核线程?

  • 内核级库是否必须只创建和管理内核线程,而不创建和管理用户线程?

  • 用户线程是否一定由用户级库而不是内核级库创建和管理?

  • 内核线程是否一定由内核级库而不是用户级库创建和管理?

书上说“Pthreads,POSIX 标准的线程扩展,可以作为用户级库或内核级库提供。”

  • PThread 在 Linux 中是内核级库,在 Windows 中是用户级库吗?

  • PThread 是否根据定义创建和管理用户线程或内核线程?

谢谢。

最佳答案

Does a user-level library necessarily create and manage only user threads but no kernel threads?

这里的“用户级库”似乎是指不依赖于允许创建和管理线程的内核系统调用的库,因此根据定义它无法创建内核线程。

这里的想法是内核仍然不知道您正在进程内进行线程化。这种方法的主要限制是此类进程同时不能使用多个处理器核心。

Does a kernel-level library necessarily create and manage only kernel threads but no user threads?

“内核级库”有点用词不当。库是一个用户空间的概念。在某些情况下,库函数和内核系统调用之间可能存在一一对应的关系,但这通常不是最实用的解决方案。

在Linux中,有一个clone系统调用可以创建一个新进程。这个新进程可以与父进程共享内存、文件描述符和其他资源。在较高层次上,我们经常将此类进程称为一个进程内的线程。直接使用系统调用通常会带来不必要的复杂性,并且使可移植性变得困难,因此通常使用用户空间库。

常用的 pthread 实现是“内核级”的,即 pthread 线程与系统线程一一对应,但在许多情况下,库函数调用不需要与系统调用一一对应。特别是,最常用的函数经过专门设计,因此在大多数情况下不需要使用系统调用。它有助于提高性能。

可以通过其他方式实现 pthread,但这似乎是最实用的。它将大多数选项留给库用户,因为内部或外部线程之间没有额外的间接级别。

Are user threads necessarily created and managed by user-level libraries not by kernel-level libraries?

“用户线程”只是内核无法识别的类似进程的结构。 “内核级”库可能会使用类似的东西。也可以直接实现它们而不使用任何库。

Are kernel threads necessarily created and managed by kernel-level libraries not by user-level libraries?

内核线程的创建依赖于创建线程的系统调用。大多数情况下它会在库中使用,但原则上您可以直接调用它们。

关于linux - 用户线程和内核线程与线程级库和内核级库是否有以下任何一种对应关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52334997/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com