This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: How to implement readers-writer lock with timeout, a hard question.
- From: Steve Munroe <sjmunroe at us dot ibm dot com>
- To: Chen(?)Jun(?) <chjfth at gmail dot com>
- Cc: libc-alpha at sourceware dot org
- Date: Tue, 15 Jan 2008 20:49:30 -0600
- Subject: Re: How to implement readers-writer lock with timeout, a hard question.
libc-alpha-owner@sourceware.org wrote on 01/15/2008 07:52:15 PM:
> Hello everyone, I'm new to mailing list. I think this list is the proper
> place to ask my question.
>
> Is there an implementation of readers-writer lock with timeout support
> on Linux(no doubt, using glibc). I've known quite some implementation of
> readers-writer lock without timeout, like that in boost and ACE(by
> Douglas C. Schmidt). By saying "timeout support", I mean, if some thread
> acquires read or write lock but fails to get it before "timeout"
> elapses, the calling thread returns as if the thread has never acquired
> lock.
>
> I had not seen an implementation on Windows 2000/XP either, but I
> managed to implement it some months ago, with help of the great
> QueueUserAPC Win32 function. Now, I'd like to know how to implement
> readers-writer lock with timeout on Linux. Can it be implemented with
> glibc or some more kernel functions must be added to fulfill this?
> Searching on google for weeks and no luck. Does anyone have an idea.
> Thanks in advance.
>
look at the posix documentation for pthread_rwlock_*. This API supports
read/write locks with and without time-out.
You can find lots of references using google. For example:
http://www.linuxhowtos.org/manpages/3p/pthread_rwlock_timedrdlock.htm