[Patch] libstdc++/24244 (2nd try)

Kurt Kohler kohler@ao.com
Tue Oct 11 21:46:00 GMT 2005


I'm sure everyone will be happy to hear that valgrind is now happy with 
my test program. It no longer complains about the uninitialized mutex. Yay!

Did anyone ever figure out why no one else could reproduce it?

It will take a bit longer to change my real program back to using the 
stdc++ shared_ptr. I'll let you know what I find although I don't expect 
any problems.

Kurt

Paolo Carlini wrote:

>Hi,
>
>so we actually have a problem with the initialization of those mutexes,
>when __GTHREAD_MUTEX_INIT is defined. The fix for this, figured out by
>Jonathan, is simple, in principle, because these objects are allocated
>on the stack, not on the heap, and we don't need complicate "once"
>logic. The only problem is that, strictly speaking, *copying* mutexes is
>not allowed: hopefully, however, the below is sufficiently portable to
>the targets we care of, certainly we are alredy using the same approach,
>involving copies, in the initializations present in mt_allocator.cc.
>
>I would ask Kurt to test this version of the patch, which works fine
>here: I believe it represents an improvement anyway, because currently,
>unfortunately, in the common case of __GTHREAD_MUTEX_INIT defined, those
>mutexes are currently not initialized at all, completely unpredictable
>behavior, we can't do worse.
>
>Thanks again to Kurt for reporting this serious issue.
>
>Paolo.
>
>/////////////////
>
>  
>
>------------------------------------------------------------------------
>
>2005-10-11  Jonathan Wakely  <redi@gcc.gnu.org>
>
>	PR libstdc++/24244
>	* include/tr1/boost_shared_ptr.h (_Sp_counted_base::_Sp_counted_base()):
>	When __GTHREAD_MUTEX_INIT is defined, initialize the mutex.
>  
>
>------------------------------------------------------------------------
>
>--- boost_shared_ptr.h.~1.3.~	2005-08-17 04:14:08.000000000 +0200
>+++ boost_shared_ptr.h	2005-10-11 12:05:14.000000000 +0200
>@@ -101,7 +101,14 @@
> 
>   _Sp_counted_base()
>   : _M_use_count(1), _M_weak_count(1)
>-  { }
>+  {
>+    // For the case of _GTHREAD_MUTEX_INIT we haven't initialised
>+    // the mutex yet, so do it now.
>+#if defined(__GTHREADS) && defined(__GTHREAD_MUTEX_INIT)
>+    __gthread_mutex_t __tmp = __GTHREAD_MUTEX_INIT;
>+    _M_mutex = __tmp;
>+#endif
>+  }
> 
>   virtual
>   ~_Sp_counted_base() // nothrow
>  
>



More information about the Libstdc++ mailing list