
Hi, This article at Dr Dobb's proposes a possible solution to the problem of simultaneously locking multiple mutexes, I haven't tested it in practice yet though: http://www.ddj.com/cpp/204801163?pgno=1 (click away the ad) Kind regards, Walter On Feb 1, 2008 1:21 PM, Kowalke Oliver (QD IT PA AS) < Oliver.Kowalke@qimonda.com> wrote:
Hi, what's the best practice in following scenario: m threads and n resources (each resource is protected by a mutex) thread x needs read/write access to resources (...i,j,k,..) threads y,z,... do access another subset of resources at the same time
inorder to protected deadlocks I would do following in the code of the different threads (code executed by the threads are different):
... try_lock: // label unique_lock< mutex > lk1( mtx1, try_to_lock_t); unique_lock< mutex > lk4( mtx2, try_to_lock_t); unique_lock< mutex > lk7( mtx3, try_to_lock_t); if ( ! ( lk1 && lk2 && lk3) ) goto try_lock; // all mutexes are locked // now modify safely resource 1,2,3 ...
Maybe you have a better pattern do solve this problem?
best regards, Oliver
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost