简体   繁体   English

关于boost :: lock_guard和boost :: unique_lock

[英]About boost::lock_guard and boost::unique_lock

I was hoping someone could tell me if my understanding on the following 3 locks is correct and possibly add to it. 我希望有人能告诉我我对以下3个锁的理解是否正确,并且有可能加进去。 my main concern is speed with minimum overhead. 我主要关心的是速度和最小的开销。

  • boost::lock_guard
  • boost::unique_lock
  • boost::scoped_lock

boost::lock_guard is the lightest kind of a lock and is only shared amongst members of a process. boost::lock_guard是最轻的一种锁,仅在进程成员之间共享。 The unique_lock is an improved version of lock_guard with more functionality. unique_lock是具有更多功能的lock_guard的改进版本。 The scoped_lock allows locking across different processes.The scoped_lock is the heaviest of all locks.Is my understanding correct. scoped_lock允许跨不同进程进行锁定。scoped_lock是所有锁中最重的锁。我的理解是正确的。 The thread here however states that scoped_lock is similar to unique_lock. 但是, 这里的线程指出scoped_lock与unique_lock相似。 if so does that mean scoped_lock is as heavy as unique_lock ? 如果是的话是否意味着scoped_lock是重unique_lock

If what you mean by heavy is the amount of overhead, then yes scoped_lock is as heavy as unique_lock, because they're the same thing. 如果您所说的繁重是开销,那么scoped_lock和unique_lock一样繁重,因为它们是同一回事。 According to this , a unique lock has a few more features than lock_guard, at the expense of a bit of overhead. 根据这个 ,独特的锁具有比lock_guard一些更多的功能,在一些开销的费用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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