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

This is a discussion on Does anyboy know a reader-writer lock implementation (other than pthread and solaris/linux kernel). - Linux ; 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() ...

+ Reply to Thread
Results 1 to 3 of 3

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

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

    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/xr...on/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,

    Mark


  2. 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/xr...on/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/bookst...922&rl=1#info4
    (select "Source Code", the rwlock*.{c,h} files).

    HTH,
    Loic.


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


    markryde@gmail.com wrote:

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


    You are gravely mistaken. Futexes are a fantastically efficient
    mechanism to deal with contention. The implementation only uses futexes
    if there is contention and does not in the uncontended case. In the
    contended case, you need some way to block the process, and futexes are
    a minimal way to do that.

    DS


+ Reply to Thread