This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]