Title
use_count and unique in shared_ptr
Status
resolved
Section
[util.smartptr.shared]
Submitter
Marshall Clow

Created on 2016-11-09.00:00:00 last changed 89 months ago

Messages

Date: 2017-02-02.00:41:18

[ Issues Telecon 16-Dec-2016 ]

Resolved by adoption of P0521R0.

Date: 2016-11-09.00:00:00

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 make unique() 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.

History
Date User Action Args
2016-12-16 20:56:38adminsetmessages: + msg8741
2016-12-16 20:56:38adminsetstatus: new -> resolved
2016-11-09 00:00:00admincreate