如何解锁 boost::upgrade_to_unique_lock (由 boost::shared_mutex 制成)?
所以我有一些shared_mutex并做到了这一点:
boost::upgrade_lock<boost::shared_mutex> lock(f->mutex);
boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
现在我想“解锁它”或者至少将其降级为类似的东西:
boost::shared_lock<boost::shared_mutex> lock_r(f->mutex);
如何做这样的事情?是否可以?
So I had some shared_mutex and done this:
boost::upgrade_lock<boost::shared_mutex> lock(f->mutex);
boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
now I want to "unlock it" or at least downgrade it to something like:
boost::shared_lock<boost::shared_mutex> lock_r(f->mutex);
How to do such thing? Is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您让
upgrade_to_unique_lock
超出范围,它将自动降级回升级所有权。例如
编辑:另一件事。如果给定函数仅需要独占锁,则可以使用
boost::unique_lock
并唯一锁定,而无需同时使用upgrade
和upgrade_to_unique
锁。If you let the
upgrade_to_unique_lock
go out of scope, it will automatically downgrade back to upgrade ownership.For example
Edit: One other thing. If a given function only requires exclusive locks, you can use
boost::unique_lock
and lock uniquely, without going through both theupgrade
andupgrade_to_unique
locks.