This fixes a tsan warning in shared_ptr by replacing the non-atomic
load with a call to _M_get_use_count() which does a relaxed atomic
load.

Tested x86_64-linux, committed to trunk. Will commit to 4.8 soon too.


commit a795f4e757d0f0ca11324a2c4f62cbe1bd876ec7
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Mon Jan 27 17:01:25 2014 +0000

        PR libstdc++/59215
        * include/bits/shared_ptr_base.h
        (_Sp_counted_base<_S_atomic>::_M_add_ref_lock()): Use relaxed atomic
        load.

diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h 
b/libstdc++-v3/include/bits/shared_ptr_base.h
index 83724e4..1c3a47d 100644
--- a/libstdc++-v3/include/bits/shared_ptr_base.h
+++ b/libstdc++-v3/include/bits/shared_ptr_base.h
@@ -233,7 +233,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     _M_add_ref_lock()
     {
       // Perform lock-free add-if-not-zero operation.
-      _Atomic_word __count = _M_use_count;
+      _Atomic_word __count = _M_get_use_count();
       do
        {
          if (__count == 0)

Reply via email to