C++ bindings for libpmemobj (part 7) - synchronization primitives
To finish off the C++ bindings to libpmemobj blog marathon, I will introduce to you the synchronization mechanisms we implemented. They are mostly C++11-like implementations of different kinds of mutexes and the condition variable. They satisfy their respective concepts (Mutex, SharedMutex and so on), the difference is that they are based on the persistent memory resident synchronization primitives provided by libpmemobj.
pmem::obj::mutex class satisfies the requirements of the Mutex and
StandardLayoutType concepts. The usage of this class should be really
straightforward for anyone who has ever used the
std::mutex. The only
difference is that the
pmem::obj::mutex has to be placed in persistent memory,
within a libpmemobj pool. This is because the implementation needs to be able to
reset the mutex the next time the pool is opened after a power failure/crash.
In persistent memory, the mutex would not be reinitialized automatically in
You can use the
pmem::obj::mutex with standard wrapper classes like:
Shared Mutex and Timed Mutex
pmem::obj::timed_mutex are also very similar
std counterparts. They also satisfy their respective SharedMutex
and TimedMutex as well as the StandardLayoutType concepts. Their usage is
also very straightforward:
pmem::obj::timed_mutex are persistent
memory resident synchronization mechanisms.
pmem::obj::condition_variable, as you probably by now noticed, is pretty
much the standard
std::condition_variable, with the exception of it being
persistent memory resident. The usage is also very similar:
With this we have ended the introduction to the core classes and functions of the C++ bindings to libpmemobj. If you ever find yourself in doubt about the usage of the C++ bindings or PMDK in general, don’t hesitate to send us a message on our Google Group.