Subj : Re: deadlock avoidance To : comp.programming.threads From : Uenal Mutlu Date : Fri May 20 2005 11:39 am "axter" wrote > Are there any good C++ methods, objects, or logic to avoid deadlocks? > > I have the following code: > http://code.axter.com/sync_ptr.h > http://code.axter.com/sync_ctrl.h > > I'm trying to figure out a way in which the smart pointer can > automatically avoid deadlocks. > > Right now I'm stuck, and I was hoping someone here could come up with > something I've overlooked, or something I'm not aware of. > > Any advice would be appreciated. I have developed a small library for this. It detects a deadlock situation and prevents it by rejecting the lock request which would cause a deadlock, and instead calls a deadlockwarn handler (which in debug build by default gives diag msg and asserts, but continues in release build). After such a situation one practically can only stop the programm or use some exception code to handle the situation in applic logic, but IMO the only correct way is simply to fix the code which leads to a deadlock situation. It does work with both recursive and non-recursive mutex types, incl. CriticalSection of Win32. If you would like to try my library (currently Win32 only) contact me via email. I personally would recommend such code for diagnosis only, but never to use it in production code, because the overhead is too high vs. a program without such checks. .