简体   繁体   中英

Easiest implement pattern 1 writer - multiple readers with boost library

I develop a module with multiple threads and one Cache in std::map. Some times I need to update cache. In that time all readers must wait, while I do update map. How can I do this synchronization with boost library?
PS: some time ago in Boost was read_write_mutex. But in current releases of Boost it missed.

will shared_mutex replace read_write_mutex ?

Yes.

...

Basically unique_lock<shared_mutex> will give you a write lock, shared_lock<shared_mutex> will give you a read lock, and upgrade_mutex<shared_mutex> will give you a read lock than you can upgrade by transferring ownership (with move) to a unique_lock<shared_mutex> .

http://lists.boost.org/Archives/boost/2008/01/132656.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM