Skip to content

nikezono/retlock

Repository files navigation

Actions Status Actions Status Actions Status codecov

ReTLock

Fast and Efficient C++ Implementation of Reentrant Locking

Usage

You can use include/retlock/retlock.hpp as the single-file header-only library.

Example

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);
} // unlocked

See example/ directory for more details.

Build (No need to do it, except for developers)

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-format

Benchmark Result

Here'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.

image

About

Reentrant lock / recursive mutex implementation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published