POSIX 线程与 Win32 线程
我刚刚涉足 POSIX 池并尝试了 POSIX 线程首次。到目前为止,我一直认为 POSIX 线程和 Win32 线程之间存在很大的体系结构差异,但从我尝试过的(确实很小)来看,我并没有真正看到任何差异。
但我仍然很好奇——POSIX 线程和 Win32 线程之间有什么区别(如果有的话)?它们是根本不同还是只是有细微差别?
I just dipped my toes into the POSIX pond and tried out POSIX threads for the first time. Until now, I'd been under the impression that there's a big architectural difference between POSIX threads and Win32 threads, but from the (admittedly little) that I tried, I didn't really see any difference.
I'm still curious though -- what are the differences (if any) between POSIX threads and Win32 threads? Are they different fundamentally, or do they just have minor differences?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Windows NT 系列内核和许多 Unix 内核中“底层”的线程管理和调度方式存在巨大差异,但这不是问题。
如果您只是谈论接口(Win32 线程和 POSIX 线程公开的服务),那么通过一些工作,您几乎可以将任何 POSIX 线程功能映射到 Win32 等效项 ~1:1。它已经完成了(参见 pthreads-win32)。
我可能注意到的一个很大的区别是,在 Win32 下,您使用实际的系统调用来处理线程,而 POSIX 线程的调用是库的一部分(pthreads< /strong>),在许多 Unix 系统下 - 调用 Unix 内核的一些非常低级的系统调用(在 Linux 下有clone())。
只是为了向您证明,除非您非常深入,否则 pthreads 没什么特别的,您可以下载 pthreads-win32,它公开了与 pthreads 完全相同的接口,并且任何函数都映射到 Win32 线程 API。它有效。
There are huge differences between how threads are managed and scheduled "under the hood" in Windows NT family kernels and on many Unix kernels, but that's not the question.
If you're just talking about the interface (the services exposed by Win32 threads and POSIX threads), with some work you can almost map any POSIX thread feature to a Win32 equivalent ~1:1. And it has been done (see pthreads-win32).
One big difference I may notice is that under Win32 you use actual system calls to work with threads, instead POSIX threads' calls are part of a library (pthreads), that - under many Unix systems - calls some very low level system calls of Unix kernels (under Linux there's clone()).
Just to prove you that, unless you go very deep, pthreads is nothing so special, you can download pthreads-win32 that exposes quite the same interface of pthreads, and any function is mapped on Win32 thread APIs. And it works.
一个微小但至关重要的区别似乎是,没有与 Windows 的
CREATE_SUSPENDED
。One small but crucial difference seems to be that there's no POSIX equivalent to Windows's
CREATE_SUSPENDED
.