This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Fw: [Boost-users] Problem with shared_ptr and pthreads_mutex_lock
Paolo Carlini wrote:
> Kurt Kohler wrote:
>
>> I should emphasize that this isn't just a problem with what valgrind
>> reports.
>
> In fact, I'm seeing something fishy in the usage of _M_mutex (i.e.,
> its initialization) in our code for shared_ptr. I will try to tell you
> more as soon as possible.
Indeed, the mutex is not initialized at all. The below is a possible,
minimal, fix (for sure we are a long way from a well tested and
optimized implementation). Can you test it (*) with your application??
Thanks,
Paolo.
(*) Just in case: given the structure of the library, rebuilding
compiler and library is not necessary, simply patching the concerned
header file in its installation place will do.
///////////////
--- boost_shared_ptr.h.~1.3.~ 2005-08-17 04:14:08.000000000 +0200
+++ boost_shared_ptr.h 2005-10-06 23:34:12.000000000 +0200
@@ -54,6 +54,11 @@
#ifndef _BOOST_SHARED_PTR_H
#define _BOOST_SHARED_PTR_H 1
+namespace __gnu_internal
+{
+ static __glibcxx_mutex_define_initialized(_M_counted_base_mutex);
+}
+
// namespace std::tr1
namespace std
{
@@ -131,7 +136,7 @@
void
add_ref_lock()
{
- __gnu_cxx::lock lock(_M_mutex);
+ __gnu_cxx::lock lock(__gnu_internal::_M_counted_base_mutex);
if (__gnu_cxx::__exchange_and_add(&_M_use_count, 1) == 0)
{
_M_use_count = 0;
@@ -145,8 +150,8 @@
if (__gnu_cxx::__exchange_and_add(&_M_use_count, -1) == 1)
{
dispose();
- __glibcxx_mutex_lock(_M_mutex);
- __glibcxx_mutex_unlock(_M_mutex);
+ __glibcxx_mutex_lock(__gnu_internal::_M_counted_base_mutex);
+ __glibcxx_mutex_unlock(__gnu_internal::_M_counted_base_mutex);
weak_release();
}
}
@@ -162,8 +167,8 @@
{
if (__gnu_cxx::__exchange_and_add(&_M_weak_count, -1) == 1)
{
- __glibcxx_mutex_lock(_M_mutex);
- __glibcxx_mutex_unlock(_M_mutex);
+ __glibcxx_mutex_lock(__gnu_internal::_M_counted_base_mutex);
+ __glibcxx_mutex_unlock(__gnu_internal::_M_counted_base_mutex);
destroy();
}
}
@@ -181,7 +186,6 @@
_Atomic_word _M_use_count; // #shared
_Atomic_word _M_weak_count; // #weak + (#shared != 0)
- __gnu_cxx::mutex_type _M_mutex;
};
template <typename _Ptr, typename _Deleter>