互斥锁和锁结构是如何实现的?
我了解锁、互斥锁和其他同步结构的概念,但是它们是如何实现的呢?它们是由操作系统提供的,还是依赖于 CPU MMU 的特殊 CPU 指令?
I understand the concept of locks, mutex and other synchronization structures, but how are they implemented? Are they provided by the OS, or are these structures dependent on special CPU instructions for the CPUs MMU?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能想查看这些链接,但主要的链接是维基百科上的测试和设置:
http://en.wikipedia.org/wiki/Test-and-set
互斥体是如何实现的?
你还可以看看这个专利:
http://www.faqs.org/patents/app/20080222331
You may want to look at these links, but the main one is the Test-and-set on Wikipedia:
http://en.wikipedia.org/wiki/Test-and-set
How are mutexes implemented?
You can also look at this patent:
http://www.faqs.org/patents/app/20080222331
正如其他人指出的那样,大多数互斥和同步机制都使用硬件原子操作。然而,完全用软件实现互斥是可能的。请参阅 Dekker 算法,以及 彼得森 和 兰波特。尽管现在硬件原子无处不在,这些主要具有历史意义,但我也研究过“有趣”的系统(仍在生产中),其中软件技术仍然是必要的。
Most mutual exclusion and synchronization mechanisms use hardware atomic operations, as others have pointed out. However, it is possible to implement mutual exclusion entirely in software. See Dekker's algorithm, and also related algorithms by Peterson and Lamport. Although these are primarily of historical interest now that hardware atomics are ubiquitous, I have worked on "interesting" systems (still in production) where software techniques are still necessary.