
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