問題描述
我正在尋找一個好的 C++ 讀寫鎖.我們有一個用例,有一個不頻繁的作者和許多頻繁的讀者,并希望為此進行優化.最好我想要一個跨平臺的解決方案,但是只有一個 Windows 是可以接受的.
I'm looking for a good reader/writer lock in C++. We have a use case of a single infrequent writer and many frequent readers and would like to optimize for this. Preferable I would like a cross-platform solution, however a Windows only one would be acceptable.
推薦答案
較新版本的 boost::thread 具有讀/寫鎖(1.35.0 及更高版本,顯然以前的版本無法正常工作).
Newer versions of boost::thread have read/write locks (1.35.0 and later, apparently the previous versions did not work correctly).
他們的名字是shared_lock
、unique_lock
和 upgrade_lock
并對 shared_mutex
.
They have the names shared_lock
, unique_lock
, and upgrade_lock
and operate on a shared_mutex
.
這篇關于C++ 中的讀/寫鎖的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!