On 2/19/2013 4:02 PM, boost-users-request-at-lists.boost.org |Boost/Allow to home| wrote:
Subject: Re: [Boost-users] [Atomic] [Tread] Proposal for Synchronized<T> Message-ID:<5123C32D.9020700@wanadoo.fr> Content-Type: text/plain; charset="iso-8859-1"; Format="flowed"
Le 19/02/13 17:58, Gabriel Bizzotto a ?crit :
Hi !
I've created two simples classes that helped me avoid data races when sharing objects among threads.
The idea is to declare objects that need for synchronization as Synchronized<T>, which holds a T and a mutex. To use the T, a Get function has to be called that returns a proxy, which holds a pointer to the T and a scoped lock on the mutex. The proxy defines operator-> and operator* to give access to the T. To have acces to the T, one has to create the proxy. As long as the proxy exists, the mutex associated with the T is locked, effectively preventing use by other threads.
I have one that does reader/writer locking. I'll pass it along for comparison along with design notes (it was done partially for teaching), if it's OK to send a zip file to you. —John