Search code examples
lockingglibgnome

Gnome library reader/writer lock implementation


The Gnome library provides a number of functions for read write locks, these are g_rw_lock_writer_lock () and g_rw_lock_reader_lock () [https://developer.gnome.org/glib/stable/glib-Threads.html#g-rw-lock-writer-lock].

Is the implementation of these functions any close to what is described in this Wikipedia article [https://en.wikipedia.org/wiki/Readers%E2%80%93writer_lock]. More specifically, in which category these functions belong a Read-preferring RW, Write-preferring RW or unspecified?

Thanks


Solution

  • Yes, GRWLock implements a standard read/write lock as described in the Wikipedia article. It has unspecified priority rules.

    On Unix systems, GRWLock is actually implemented using the pthread_rwlock_*() functions. These also have unspecified priority rules, but this at least means you know it will behave the same as most other read/write lock implementations on your system.