Subj : Re: Lock free t-safe smart pointer based on double linked list To : comp.programming.threads From : axter Date : Sun May 15 2005 11:27 am Joe Seigh wrote: > On 12 May 2005 22:20:56 -0700, axter wrote: > > > > > rGlory wrote: > >> > >> There is another problem though. To use such structure as SP I need > > to > >> put a pointer into struct item. It is not clear to me how to safely > >> assign such pointer when "everything can change any time". > >> > >> Any ideas? > > > > For a thread safe C++ smart pointer, check out the following link: > > http://code.axter.com/sync_ptr.h > > > > The sync_ptr smart pointer is a wrapper class that can make the > > instance of any object thread safe. In windows it can use critical > > section logic or mutex, and in UNIX/Linux it uses POSIX mutex logic. > > > > > How do you avoid deadlock? > > thread 1: x->f(&(y->g()); > thread 2: y->f(&(x->g()); > > > -- > Joe Seigh > > When you get lemons, you make lemonade. > When you get hardware, you make software. Good question. The code doesn't have the ability to stop a deadlock. I'm currently working on a method that can be used to avoid a deadlock via trylock method. .