Abseil/nsync Mutex

139 views
Skip to first unread message

Dmitry Vyukov

unread,
Feb 20, 2019, 3:59:28 AM2/20/19
to lock...@googlegroups.com
Hi,

FYI, if you haven't seen this yet:
https://github.com/abseil/abseil-cpp/blob/master/absl/synchronization/mutex.h
https://github.com/abseil/abseil-cpp/blob/master/absl/synchronization/mutex.cc

Some minor improvements are possible, but overall it's a piece of art.
Originally developed by Mike Burrows
(https://en.wikipedia.org/wiki/Michael_Burrows). If you like learning
synchronization primitives, this one will be a good time investment.
The main design goal I guess is handling all possible usage scenarios
gracefully (i.e. not just readers, or writers, or light contention, or
heavy contention, or few waiters, or thousands of waiters, etc) which
is expected of a primitive used in literally millions of place across
thousands of systems. It also has some interesting features like
contention profiling and deadlock detection. FWIW it also fits into a
single intptr (i.e. 4 bytes on 32-bit systems).

There is also a bit simplified version of the same algo in nsync library:
https://github.com/google/nsync/blob/master/README
https://github.com/google/nsync/blob/master/internal/mu.c
It's C and does not have contention profiling and deadlock detection,
so may be easier for leaning of the mutex algorithm itself.

Chris M. Thomasson

unread,
Feb 20, 2019, 4:35:19 AM2/20/19
to Scalable Synchronization Algorithms
Interesting! Will take a look. Thank you for the heads up Dmitry. :^) 
Reply all
Reply to author
Forward
0 new messages