Boost logo

Boost Users :

Subject: Re: [Boost-users] [Locks/Mutex] choices between types
From: Igor R (boost.lists_at_[hidden])
Date: 2009-07-01 16:43:23


> Since the "lock" et "mutex" types provide ways to lock/unlock access to
> resources, why are not these types defined under the same name ? Are the
> concepts they implements much more different than I think ?

As Markus mentioned, lock objects are just raii-style helpers for
exception safe locking.
As for multiple mutex types, they stand for different approaches to
the resource sharing problem. If you just want to always lock your
resource exclusively, use simple "mutex" class; if you prefer to allow
simultaneous shared access as long as there're readers only, use
shared_mutex; and if you'd like to be able to lock the mutex several
times from the same thread, use recursive_mutex (like this: {
mutex_.lock(); mutex_.lock(); /*....*/ mutex_.unlock();
mutex_.unlock(); }


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net