Monday, May 07, 2018

An Implementation of Phase-Fair Reader/Writer Locks

DZone Database Zone
An Implementation of Phase-Fair Reader/Writer Locks
An Implementation of Phase-Fair Reader/Writer Locks

We were in search for some C++ read-write lock implementation that allows a thread to acquire a lock and then optionally pass it on to another thread. The C++11 and C++14 standard library lock implementations std::mutex and shared_mutex do not allow that (it would be undefined behavior. By the way, it's also undefined behavior when doing this with the pthreads library).

Additionally, we were looking for locks that would neither prefer readers nor writers so that there will be neither reader starvation nor writer starvation. And then, we wanted concurrently queued read and write requests that compete for the lock to be brought into some defined execution order. Ideally, queued operations that cannot instantly acquire the lock should be processed in approximately the same order in which they queued.

No comments:

Fun With SQL: Functions in Postgres

DZone Database Zone Fun With SQL: Functions in Postgres In our previous  Fun with SQL  post on the  Citus Data  blog, we covered w...