Thanks for the response. What if I place accesses to the global pointer within critical sections (indicated by mutex.lock()-unlock()) ? I've enclosed the dominant portions of the code in while loops. Does this make it thread safe ?
<code>
//initializion Thread (runs before any other thread): shared_ptr< MyClass > global_ptr(createNewObject()) ;
//WriterThread :
while(true) {mutex.lock()global_ptr.reset( createNewObject())mutex.unlock();sleep (5) ;}
//ReaderThreads:
mutex.lock()weak_ptr<MyClass> local_weak_ptr (globally_ptr) ;mutex.lock()...while(true) {if(shared_ptr< MyClass > local_shared_ptr = local_weak_ptr.lock() ) { // using local_shared_ptr.} else { // recreate weak ptr from global ?}} // end of while loop
</code>
From: Gottlob Frege
From the boost documentation, it appears that this could be an undefined operation as the global shared pointer is being read and written to by multiple threads. Is that correct ?
In case the link fails or someone wants more details, please read on. I've got a n reader threads and 1 writer thread. initializion Thread : shared_ptr< MyClass > global_ptr(createNewObject()) ; WriterThread :global_ptr.reset( createNewObject()) ReaderThreads:weak_ptr<MyClass> local_weak_ptr (globally_ptr) ;... if(shared_ptr< MyClass > local_shared_ptr = local_weak_ptr.lock() ) { // using local_shared_ptr.} else { // recreate weak ptr from global ?} thanks. Rajeev I don't think that code is thread-safe. You can modify the shared count safely between threads, but you can't modify the pointer itself. Tony -----Inline Attachment Follows----- _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users