3rdParty/boost/1.78.0/libs/flyweight/doc/reference/locking.html
A mutex is a type whose objects can be in either of two states, called locked and unlocked, with the property that when a thread A has locked a mutex m and a different thread B tries to lock m, B is blocked until A unlocks m. Additionally, a mutex is said to support recursive locking if a thread can succesfully invoke the locking operation for a mutex already locked by this same thread; in this case, it is required that the thread execute as many unlock operations as lock operations it has performed for the mutex to become effectively unlocked. A scoped lock is a type associated to some mutex type whose objects do the locking/unlocking of a mutex on construction/destruction time.
In the following table, Mutex is a mutex type, m is an object of type Mutex, Lock is a scoped lock associated to Mutex and lk is a value of Lock.
Mutex and Scoped Lock requirements. | expression | return type | assertion/note
pre/post-condition |
| --- | --- | --- |
| Mutex m; | | Post: m is unlocked. |
| (&m)->~Mutex(); | void | Pre: m is unlocked. |
| Lock lk(m); | | Associates m to lk and locks m. |
| (&lk)->~Lock(); | void | Unlocks the mutex associated to lk. |
These concepts are very similar, but not entirely equivalent, to the homonym ones described in the Boost Thread Library.
Locking policies describe a mutex type and an associated scoped lock type. flyweight uses a given locking policy to synchronize the access to its internal factory.
A type Locking is a locking policy if:
One of the following conditions is satisfied:
is_locking<Locking>::type is boost::mpl::true_,Locking is of the form locking<Locking'>.The type Locking::mutex_type (or Locking'::mutex_type if (b) applies) is a model of Mutex and supports recursive locking.
The type Locking::lock_type (or Locking'::lock_type if (b) applies) is a Scoped Lock of the mutex referred to above.
"boost/flyweight/locking_tag.hpp" synopsisnamespaceboost{namespaceflyweights{structlocking\_marker;template\<typenameT\>structis\_lockingtemplate\<typenameT\>structlocking;}// namespace boost::flyweights}// namespace boost
is_lockingUnless specialized by the user, is_locking<T>::type is boost::mpl::true_ if T is derived from locking_marker, and it is boost::mpl::false_ otherwise.
lockinglocking<T> is a syntactic construct meant to indicate that T is a locking policy without resorting to the mechanisms provided by the is_locking class template.
"boost/flyweight/simple_locking_fwd.hpp" synopsisnamespaceboost{namespaceflyweights{structsimple\_locking;}// namespace boost::flyweights}// namespace boost
simple_locking_fwd.hpp forward declares the class simple_locking.
"boost/flyweight/simple_locking.hpp" synopsissimple_lockingLocking Policy that specifies a basic mutex type based on the simplest synchronization mechanisms provided by the environment; When no threading capabilities are available, simple_locking specifies a dummy type without actual synchronization capabilities.
"boost/flyweight/no_locking_fwd.hpp" synopsisnamespaceboost{namespaceflyweights{structno\_locking;}// namespace boost::flyweights}// namespace boost
no_locking_fwd.hpp forward declares the class no_locking.
"boost/flyweight/no_locking.hpp" synopsisno_lockingNull Locking Policy: it specifies a dummy type that satisfies the formal requirements for the Mutex concept but does not perform thread blocking. no_locking should only be used in single-threaded environments.
Revised March 9th 2010
© Copyright 2006-2010 Joaquín M López Muñoz. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)