Re: POSIX rwlocks vs. glib2 rwlocks



On Sat, 16 Jun 2001, Erik Walthinsen wrote:

> Date: Sat, 16 Jun 2001 19:15:33 -0700 (PDT)
> From: Erik Walthinsen <omega temple-baptist com>
> To: gtk-devel-list gnome org
> Subject: POSIX rwlocks vs. glib2 rwlocks
>
> While investigating the g_type_instance_is_a() performance problem, I
> looked into how rwlocks are done in glib2.  I was surprised to learn that
> there is no implementation of rwlocks that uses the pthread functions
> that implement this primitive.  glibc-2.2 has rwlocks fully implemented
> from what I can see in the library and headers (though I haven't confirmed
> that they are fully functional, I would assume so), and I have little
> doubt that they're faster than the routines currently in glib.

Read-write locks are functional, and also provide several flavors of
lock: writer preference, reader preference, and writer preference
without recursive read locking.

Writer precedence is the default type, and supports recursive read
locking as well, which is tricky (what if a thread which owns a read
lock wants to get another read on the same lock, but writers have
queued up in the meanwhile? POSIX requires that the reader is granted
the additional lock, and the glibc2 implementation makes it work
correctly).

> If I have time, I'll make an attempt at rewriting the rwlocks to use
> pthreads on architectures where they work.  Problem is going to be those
> static rwlocks... ;-(

In glibc you have the PTHREAD_RWLOCK_INITIALIZER for those. I think
that's a Unix 98 (and POSIX draft) feature.





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]