Re: [Boost-bugs] [Boost C++ Libraries] #12309: Is "Reference counting" example misleading and wrong?

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #12309: Is "Reference counting" example misleading and wrong?
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-09-14 19:20:38

#12309: Is "Reference counting" example misleading and wrong?
  Reporter: Adam Badura | Owner: timblechmann
  <adam.f.badura@…> | Status: closed
      Type: Bugs | Component: atomic
 Milestone: To Be Determined | Severity: Cosmetic
   Version: Boost 1.61.0 | Keywords: atomic, shared_ptr,
Resolution: fixed | reference counting, documentation
Changes (by andysem):

 * status: new => closed
 * resolution: => fixed


 I think the code in the documentation is valid.

 The release semantics is needed to guarantee that any modifications made
 by a thread before it decrements the counter are visible to other threads.

 The acquire semantics is only needed if the object destructor is called.
 It makes sure that the destructor observes the actual state of the object
 that might have been modified by another thread that previously
 decremented the counter from 2 to 1. The standard (C++11,
 [atomics.fences]/4) says that in this code the
 `atomic_thread_fence(acquire)` synchronizes with `fetch_sub(1, release)`
 issued by other threads, so it should not be reordered with the

 It is formally correct to merge this acquire fence with the `fetch_sub`
 operation, but depending on the CPU architecture it may or may not be
 slightly slower.

 As for `boost::shared_ptr`, you can propose the change to that library.
 Boost.SmartPtr predates Boost.Atomic, so it contains its own
 implementation of atomic operations for many platforms.

Ticket URL: <>
Boost C++ Libraries <>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:20 UTC