1

I was hoping someone could tell me if my understanding on the following 3 locks is correct and possibly add to it. 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. The unique_lock is an improved version of lock_guard with more functionality. The scoped_lock allows locking across different processes.The scoped_lock is the heaviest of all locks.Is my understanding correct. The thread here however states that scoped_lock is similar to unique_lock. if so does that mean scoped_lock is as heavy as unique_lock ?

Community
  • 1
  • 1
MistyD
  • 16,373
  • 40
  • 138
  • 240
  • Can you clarify which Boost library you're asking about? The question you linked to is discussing Boost.Thread, but that library doesn't contain a class called `scoped_lock` at the namespace level (only class level typedefs). You also mention sharing between processes which suggests Boost.Interprocess (which features a class called `scoped_lock` in the `boost::interprocess` namespace). Thanks. – Andrew Durward May 15 '13 at 12:00

1 Answers1

0

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. According to this, a unique lock has a few more features than lock_guard, at the expense of a bit of overhead.

Joe Runde
  • 253
  • 2
  • 8