POSIX 线程在 Linux 上是如何实现的?

发布于 2024-11-05 10:57:24 字数 76 浏览 0 评论 0原文

我想知道通过 pthreads 库创建的线程实际上是内核级线程还是与内核无关的用户空间线程?我听到过对此相互排斥的意见,所以我想知道真相。

I was wondering if threads created via the pthreads library are actually kernel-level threads or user-space threads that have nothing to do with the kernel? I have heard mutually exclusive opinions about this, so I want to know the truth.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无妨# 2024-11-12 10:57:24

在 Linux 2.6 之前,它们本质上是用户空间线程,是粘合在一起的独立进程,因为内核没有真正的线程支持。编辑:2.6 之前对内核级线程(clone() 函数)有一些有限的支持,但它不与 posix 线程一起使用,仅与名为 linuxthreads 的替代线程库一起使用。
自从 NPTL(本机 Posix 线程库)出现以来,它们都是内核线程。

Before Linux 2.6 they were essentially userspace threads, separate processes which were glued together, because the kernel had no real thread support. Edit: There was some limited support for kernel level threads (a clone() function) before 2.6, but it wasn't used with posix threads, only with an alternative thread library called linuxthreads.
Since the arrival of NPTL (Native Posix Thread Library) the are kernel threads.

穿透光 2024-11-12 10:57:24

Linux 上 pthread_create() 创建的线程始终是内核级线程。 LinuxThreads 并不完全符合 POSIX(同一进程中的线程具有不同的 pid,信号处理与 POSIX 要求的不同,...),因此创建 NPTL 来解决这些问题。

有些库实现了用户级线程(例如:GNU pth,p 代表“可移植”),但它们不使用 POSIX 线程 API。

Threads created by pthread_create() on Linux have always been kernel-level threads. LinuxThreads didn't comply fully with POSIX (threads in a same process had different pid's, signal handling was different than what POSIX requires, ...), so NPTL was created to fix those issues.

There are libraries that implement user-level threads (e.g: GNU pth, the p is for Portable), but they don't use the POSIX thread API.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文