Re: [Boost-users] [Atomic] [Tread] Proposal for Synchronized<T>

Hi,
I've been working already on a synchronized_value class that is in trunk [1]. I plan to merge it to release branch as soon as I have finished the tests and the documentation. You can see some examples in [2] and [3].
I've take a look to your class and I think my class provides everything yours provide.
Surely your version has been given more thought.
My class allows in addition to lock several synchronized values using the deadlock free lock algorithm as e.g.
I did not understand the unique_synchronize part, though.
Please could you compare your class to mine and let me know what do you think?
I can't see any flaw right now, but I'm still playing with it. If anything shows up I'll let you know. Thanks !

Le 20/02/13 03:08, Gabriel Bizzotto a écrit :
My class allows in addition to lock several synchronized values using the deadlock free lock algorithm as e.g.
I did not understand the unique_synchronize part, though.
synchronize() returns a strict_lock_ptr which is something like a lock_guard that is not Lockable. unique_synchronize() returns a unique_lock_ptr which is something like a unique_lock (Lockable) and can be used with dead-lock free algorithms. This facility can be used when locking several synchronized_value instances to avoid dead-lock. this dead-lock algorithm is used e.g. to define the assignment operation as follows synchronized_value& operator=(synchronized_value const& rhs) { if(&rhs != this) { unique_lock<lockable_type> lk1(mtx_, defer_lock); unique_lock<lockable_type> lk2(rhs.mtx_, defer_lock); lock(lk1,lk2); value_ = rhs.value_; } return *this; } so that //thread1 a=b // thread2 b=a will not dead-lock. Best, Vicente
participants (2)
-
Gabriel Bizzotto
-
Vicente J. Botet Escriba