Re: Does anyboy know a reader-writer lock implementation (other than pthread and solaris/linux kernel).

Hello Mark,


I am looking for a reader-write lock implementation written in "C" for
learning the algorithm
of the classic reader-writer synchronization (Many readers, one

I found one such implementation in glibc, under nptl, with the
pthread_rwlock_init (), pthread_rwlock_rdlock(),
pthread_rwlock_wrlock() and other pthread_rwlock() method.

This implementation seems quite heavy; for example, if you look at
nptl/sysdeops/pthread/pthread_rwlock_rdlock.c (and other modules of
pthread rwlock)
you will see usage of futexes.

I found another implementation , which is quite different, in the open
solaris kernel

Also this implementation seems quite heavy.

If I remeber well, in linux kernel the rwlock is implemented using
assembler mostly.

Does anybody know and recommend about a rwlock implementation which is
simpler ?


David Butenhof gives in "Programming with POSIX threads" a possible
implementation of pthread_rwlock* functions using only traditional
synchronization mechanism: mutexes and condition variables. See chap.
7.2.1, pp253-269.

You can view the source code at:
(select "Source Code", the rwlock*.{c,h} files).