I'm going to use boost::mutex from boost/thread/mutex.hpp.
There are several ways to lock/unlock mutex: with scoped_lock, unique_lock, lock_guard, mutex's member functions ::lock() and ::unlock() and nonmember functions lock() and unlock().
I noticed, that boost::scoped_mutex is one of the most popular ways of using mutex. Why is it preferable to member functions ::lock() and ::unlock()?
Particularly, why should I use
{
boost::scoped_lock lock(mutex)
// ...
// read/output sharing memory.
// ...
}
rather than
mutex.lock()
// ...
// read/output sharing memory.
// ...
mutex.unlock()
is scoped_lock better just because of some style-coding point of view or is ::lock()/::unlock() not "thread safe enough"?