Problem with shared_ptr and pthreads_mutex_lock
I've run into a strange problem using shared_ptr which I've reduced to
the following simple case.
#include
Kurt Kohler wrote:
I've run into a strange problem using shared_ptr which I've reduced to the following simple case.
#include
class X { public: typedef std::tr1::shared_ptr<X> Ptr;
int x; };
int main(int argc, char *argv[]) { for (int i = 0; i < 100; i++) { X::Ptr pX(new X); }
return EXIT_SUCCESS; }
Compiling with g++ 4.0.1 on a Debian system with "-O0 -g -fno-inline -DDEBUG". When this program is run under Valgrind (MemCheck) repeated messages like the following occur.
==9950== Conditional jump or move depends on uninitialized value(s) ==9950== at 0x1BBB6D9A: pthread_mutex_lock (in /lib/tls/libpthread-2.3.5.so) ==9950== by 0x1BB56C75: pthread_mutex_lock (in /lib/tls/libc-2.3.5.so) ==9950== by 0x804BF29: __gthread_mutex_lock(pthread_mutex_t*) (gthr-default.h:510) ==9950== by 0x8057ACD: std::tr1::_Sp_counted_base::release() (boost_shared_ptr.h:148)
You seem to be using libstdc++'s implementation of shared_ptr; if the problem doesn't occur with boost::shared_ptr, a better place to ask this question would be libstdc++'s own mailing list.
Your reply actually help me fix the problem! I wasn't aware that the boost and tr1 versions of shared_ptr are different. When I changed my code to use the boost version, the problem went away. I'll have to see if I can figure out where to report the bug. Thanks! Peter Dimov wrote:
Kurt Kohler wrote:
I've run into a strange problem using shared_ptr which I've reduced to the following simple case.
#include
class X { public: typedef std::tr1::shared_ptr<X> Ptr;
int x; };
int main(int argc, char *argv[]) { for (int i = 0; i < 100; i++) { X::Ptr pX(new X); }
return EXIT_SUCCESS; }
Compiling with g++ 4.0.1 on a Debian system with "-O0 -g -fno-inline -DDEBUG". When this program is run under Valgrind (MemCheck) repeated messages like the following occur.
==9950== Conditional jump or move depends on uninitialized value(s) ==9950== at 0x1BBB6D9A: pthread_mutex_lock (in /lib/tls/libpthread-2.3.5.so) ==9950== by 0x1BB56C75: pthread_mutex_lock (in /lib/tls/libc-2.3.5.so) ==9950== by 0x804BF29: __gthread_mutex_lock(pthread_mutex_t*) (gthr-default.h:510) ==9950== by 0x8057ACD: std::tr1::_Sp_counted_base::release() (boost_shared_ptr.h:148)
You seem to be using libstdc++'s implementation of shared_ptr; if the problem doesn't occur with boost::shared_ptr, a better place to ask this question would be libstdc++'s own mailing list.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
I've verified to my own satisfaction that the gcc and boost versions are *not* the same, since the boost version doesn't have the bug I was seeing. I'm not exactly sure where to report stdc++ library bugs, but I subscribed to the mailing list so I assume I'll find out. Kurt John Maddock wrote:
#include
Isn't that the gcc implementation of shared_ptr? Or is it the same as the Boost version? Maybe this would be better filed as a gcc stdlib bug.
John.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
John Maddock
-
Kurt Kohler
-
Peter Dimov