Title
Semantics for destroying the deleter and the control-block of a shared_ptr are unclear
Status
nad
Section
[util.smartptr.shared.dest]
Submitter
United States

Created on 2017-02-03.00:00:00 last changed 82 months ago

Messages

Date: 2017-07-15.23:15:19

[ 2017-07 Toronto Thurs Issue Prioritization ]

NAD; Alisdair to provide rationale

Date: 2017-02-03.00:00:00
Addresses US 134

The semantics for destroying the deleter and the control-block are unclear. In particular, it is not clear that we guarantee a lack of race conditions destroying the control-block and deleter. Possible race-free implementations might destroy the deleter after running d(p), and before giving up the weak reference held by this shared_ptr; running the destructor for d only when the last weak_ptr is destroyed, potentially at a much later date, but ensuring that d(p) completes before the shared_ptr gives up its weak reference; making a copy of d in the destructor before manipulating the weak count, and then using this copy to run d(p), even while the control-block could be concurrently reclaimed with an expiring weak_ptr in another thread. Note that this may be related to LWG 2751. (Also, see the note in 20.11.2.2.10 p1 [util.smartptr.getdeleter])

Proposed change: Clarify that the shared_ptr weak ownership of the control block is released at the end of the destructor, and not as the destructor begins. Otherwise, the deleter might be destroyed even before the destructor gets to move a copy to call safely.

History
Date User Action Args
2017-07-15 23:15:19adminsetmessages: + msg9393
2017-07-15 23:15:19adminsetstatus: new -> nad
2017-02-03 00:00:00admincreate