How to write a Reader/Writer lock with timeout, using conditional variables in C/C++?
You may take a look at the source of Java's implementation ReentrantReadWriteLock.
Just grab the JDK unpack the src.zip file and search for the source.
There is no support for such things in current standard C++, although C++0x will have some threading support (I haven't checked to see how much). Therefore, any answer would have to be platform-dependent, using platform in a very general sense.
It is possible to write libraries that will behave similarly across different underlying systems, and there are quite a few cross-platform libraries. (These are subject to inefficiencies, of course, if the capabilities of the underlying platforms are different.) There could be a generally accepted C++ threading library that would work on Windows and Unix-based systems (which is almost anything you'd be running on a desktop nowadays), but I don't know of one offhand.
Therefore, this question can't really be answered as asked. It would be necessary to answer it on a particular platform or library, and none is specified. It would make sense if coupled with a request for a library recommendation.
If you're just looking for a library, Boost.Thread might do what you want.
Take a look at the Boost.Thread library. Specifically: shared_mutex
and upgradeable_mutex
objects.