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



Hello Mark,

Hello,

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
writer).

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
see:
http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/common/os/rwlock.c

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 ?

Regards,

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:
http://www.awprofessional.com/bookstore/product.asp?isbn=0201633922&rl=1#info4
(select "Source Code", the rwlock*.{c,h} files).

HTH,
Loic.

.