Manges, Ross G wrote:
I've been experiencing trouble with shared_ptrs in a multithreaded environment. First, I noticed that the ref count wasn't being locked when updated by multiple threads (shared_count.hpp). I recompiled the boost library with BOOST_HAS_THREADS defined the user.hpp, and now I can verify that the scoped_lock is being used, but I'm still seeing the same kind of problems. The traces happen in different places each time, but in general it appears that the ref count is being decremented to zero inappropriately, which in turn sometimes causes the dreaded "assert px != 0" message. See the example traces below. Please let me know if you have any suggestions on how I might proceed to debug this problem. Thanks!
Two questions: - Is it possible that some parts of your code are compiled without BOOST_HAS_THREADS?
#5 0xb73aac18 in boost::shared_ptr<Connector>::operator= ( this=0xb65e0ce4, r=@0xb6c01b18) at shared_ptr.hpp:148 #6 0xb73a974e in Listener::run ( this=0xb6c02f68) at Adapter.cpp:966
- Is it possible that you are assigning to the shared_ptr<Connector> object and at the same time reading it (making a copy of it, for example) or even assigning or resetting it from a different thread?