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
replaceread_write_mutex
?Yes.
...
Basically
unique_lock<shared_mutex>
will give you a write lock,shared_lock<shared_mutex>
will give you a read lock, andupgrade_mutex<shared_mutex>
will give you a read lock than you can upgrade by transferring ownership (with move) to aunique_lock<shared_mutex>
.
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.