计算机与现代化 ›› 2011, Vol. 193 ›› Issue (9): 215-219.doi: 10.3969/j.issn.1006-2475.2011.09.058

• 应用与开发 • 上一篇    下一篇

临界区读写锁的实现

孙建杰,陈佳品   

  1. 上海交通大学微纳科学技术研究院,上海 200240
  • 收稿日期:2011-04-20 修回日期:1900-01-01 出版日期:2011-09-22 发布日期:2011-09-22

]Implementation of Reader-writer Lock by Critical Section

SUN Jian-jie, CHEN Jia-pin   

  1. Research Institute of Micro/Nano Science and Technology, Shanghai Jiao Tong University, Shanghai 200240, China
  • Received:2011-04-20 Revised:1900-01-01 Online:2011-09-22 Published:2011-09-22

摘要: 针对Windows环境下多线程同步缺乏标准的读写锁机制,本文逐步论述利用临界区对读写锁的3种实现方式。通过对不同数量的临界区进行组合操作,可以达到读写锁的设计目的,并产生不同的读/写优先倾向。由于尝试在多线程中对读写锁进行复杂的交叉操作,故进一步对特定环境下的临界区内部细节进行分析和测试,并最终确保利用临界区实现读写锁的可靠性。最后是对读写锁尝试加解锁补充功能的一些讨论。

关键词: 多线程同步, 读写锁, 临界区, 死锁, 写优先

Abstract: For the lack of a standard reader-writer lock mechanism for the multi-thread synchronization in the Windows environment, the paper discusses three implementations on the reader-writer lock in use of the critical section and gradually reveals the advantages and disadvantages. The design of a reader-writer lock can be achieved by numbers of critical sections, and the different combinations will have the diverse read / write priority tendencies. Because multiple threads try to enter and leave the readerwriter lock on the complex cross-operation, there needs further analysis and testing for the internal details of the critical section in the specific circumstances to ultimately ensure the reliability of the reader-writer lock’s implementation. The paper also provides some details on try-lock mechanism.

Key words: multi-thread synchronization, reader-writer lock, critical section, dead lock, write priority

中图分类号: