条件变量是如何实现的?
这让我困惑了很长时间。
给定基本的原子原语,例如比较和比较swap,我可以看到如何实现自旋锁(我可以从中构建互斥体)。
但是,我不知道如何从中构建条件变量。这是怎么做到的?
This has baffled me for a long time.
Given basic atomic primitives like compare & swap, I can see how to implement a spin lock (from which I can build mutexes).
However, I don't see how I can build condition variables out of this. How is this done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这并不是特别简单。以下是 Douglas Schmidt(他主要负责 ACE 库)撰写的一篇论文的链接,该论文详细介绍了使用 Win32(Vista 之前)中可用的同步原语在 Windows 上实现条件变量的几种方法。这些方法包括仅使用基本的、通常在任何操作系统原语上可用的方法,并讨论这些方法的各种限制:
底线(结束语):
请注意,从 Vista 开始,Windows 支持使用本机 API 的条件变量:
It's not particularly simple. The following is a link to a paper by Douglas Schmidt (who is also largely responsible for the ACE libraries) that details several approaches for implementing condition variables on Windows using the synchronization primitives available in Win32 (pre-Vista). The approaches include using only the basic, generally available on any OS primitives, and discusses the various limitations of the approaches:
The bottom line (concluding remarks):
Note that starting in Vista, Windows supports condition variables using native APIs: