Which is preferred boost::lock_guard or boost::mutex::scoped_lock?
I’m using Boost.Thread with the hope to move to C++11 threading when it becomes available.
Is scoped_lock part of the next c++ standard?
Are the any advantages to prefer one over the other?
NOTE: I’m aware that scoped_lock is just a typedef of lock_guard.
edit: I was wrong scoped_lock is not a typedef of lock_guard. It’s a typedef of unique_lock.
Amit is right:
boost::mutex::scoped_lockis atypedefforboost::unique_lock<boost::mutex>, notlock_guard.scoped_lockis not available in C++0x.Unless you need the flexibility of
unique_lock, I would uselock_guard. It is simpler, and more clearly expresses the intent to limit the lock to a defined scope.