This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of Resolved status.
use_count
and unique
in shared_ptr
Section: 20.3.2.2 [util.smartptr.shared] Status: Resolved Submitter: Marshall Clow Opened: 2016-11-09 Last modified: 2020-09-06
Priority: Not Prioritized
View all other issues in [util.smartptr.shared].
View all issues with Resolved status.
Discussion:
Addresses CA 14
The removal of the "debug only" restriction for
use_count()
and unique()
in shared_ptr
introduced a bug: in order for unique()
to produce
a useful and reliable value, it needs a synchronize clause to
ensure that prior accesses through another reference are visible to the
successful caller of unique()
. Many current implementations use
a relaxed load, and do not provide this guarantee, since it's not stated in the
Standard. For debug/hint usage that was OK. Without it the specification is
unclear and misleading.
Proposed change:
A solution could makeunique()
use memory_order_acquire
, and
specifying that reference count decrement operations synchronize with
unique()
. This won't provide sequential consistency but may be useful.
We could also specify use_count()
as only providing an unreliable hint
of the actual count, or deprecate it.
[Issues Telecon 16-Dec-2016]
Resolved by adoption of P0521R0.
Proposed resolution: