Skip to content

Add promotable shared mutex inside a thread support lib. Move rsm into thread support lib

Griffith requested to merge ggriffith/BCHUnlimited:add-threadsupport-lib into dev

Notes

This MR adds a lib with a promotable shared mutex and moves rsm into that same lib. I included the lib into the repo using git subtree and will pull in any updates from the upstream using the same technique.

The behaviour of the promotable shared mutex is the same as a std::shared_mutex with the additional capability for promotion of a single thread from shared to exclusive ownership. It has the same undefined behaviour guarantees for locking and unlocking as a std::shared_mutex. Additionally, identical to std::shared_mutex, the maximum number of possible shared owners is guaranteed to be at least 10000.

Only one thread is allowed to request promotion at a time. If a thread is waiting for promotion and a second thread tries to request promotion, the request will fail to prevent starvation.

The test coverage should be complete of all locking scenarios. When compiled with debug enabled, logic errors will be thrown for bad unlocking behaviour with respect to counts of locks not which thread did the locking.

Relevant documentation and links

initial proposal: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3568.html
STL shared_mutex implementation (does not handle upgrades): https://gcc.gnu.org/onlinedocs/gcc-10.2.0/libstdc++/api/a00167_source.html

Edited by Griffith

Merge request reports