HomePhabricator

c++11: don't throw from the reverselock destructor
89f71c68c0feUnpublished

Unpublished Commit ยท Learn More

Repository Importing: This repository is still importing.

Description

c++11: don't throw from the reverselock destructor

noexcept is default for destructors as of c++11. By throwing in reverselock's
destructor if it's lock has been tampered with, the likely result is
std::terminate being called. Indeed that happened before this change.

Once reverselock has taken another lock (its ctor didn't throw), it makes no
sense to try to grab or lock the parent lock. That is be broken/undefined
behavior depending on the parent lock's implementation, but it shouldn't cause
the reverselock to fail to re-lock when destroyed.

To avoid those problems, simply swap the parent lock's contents with a dummy
for the duration of the lock. That will ensure that any undefined behavior is
caught at the call-site rather than the reverse lock's destruction.

Barring a failed mutex unlock which would be indicative of a larger problem,
the destructor should now never throw.

Details

Provenance
Cory Fields <cory-nospam-@coryfields.com>Authored on Jan 5 2016, 21:10
deadalnixPushed on May 14 2017, 22:04
Parents
rABC76ac35f36d87: c++11: detect and correct for boost builds with an incompatible abi
Branches
Unknown
Tags
Unknown

Event Timeline

Cory Fields <cory-nospam-@coryfields.com> committed rABC89f71c68c0fe: c++11: don't throw from the reverselock destructor (authored by Cory Fields <cory-nospam-@coryfields.com>).Jan 5 2016, 22:17