Fast and Efficient C++ Implementation of Reentrant Locking
You can use include/retlock/retlock.hpp as the single-file header-only library.
It's compatible with std::recursive_mutex.
#include "retlock/retlock.hpp"
retlock::RetLock lock;
lock.lock();
// something critical...
lock.lock(); // recursive locking is allowed
lock.unlock();
lock.unlock();#include "retlock/retlock.hpp"
#include <mutex>
retlock::ReTLock lock;
// recursive locking with scoped lock pattern
{
std::unique_lock<retlock::ReTLock> ul(lock);
std::unique_lock<retlock::ReTLock> ul2(lock);
} // unlockedSee example/ directory for more details.
To build the benchmark & test cases, use the followings:
# build
cmake -S all -B build
cmake --build build
# run benchmark
./build/benchmark/ReTLockBench --help
# run tests
ctest --test-dir build
or
./build/test/ReTLockTests
# format code
cmake --build build --target format
cmake --build build --target fix-formatHere's the throughput from testing on AWS EC2 m8g.16xlarge. All implementations except std::recursive_mutex are in this repository, where options are varied.
You can use +AFS,AS with the simplest declaration retlock::RetLock.
Check out the code in the benchmark directory for details.