Boost logo

Boost :

From: Anthony Williams (anthony_w.geo_at_[hidden])
Date: 2005-09-09 08:34:14


"John Maddock" <john_at_[hidden]> writes:

>>If priority policy is the overriding issue, I recommend considering
>>Alexander Terekhov's algorithm summarized here:
>
> Interesting, clearly using interlocked operations where possible is a real
> win, and would certainly be easy to implement on Win32.
>
> Unfortunately, I don't believe the algorithm you provide is compatible with
> the current interface, which promises to let the user choose how to schedule
> interleaves between readers and writers. On the other hand, it is that
> interface which is part of the problem: it introduces too much complexity,
> and too many code-paths through which locking could occur to be able to
> analyse the code easily. So maybe we should dump the current interface.

Attached is a sample implementation of a read-write-mutex for win32. It uses
my new version of call_once to initialize itself. It doesn't support different
scheduling priorities, but tries to be fair to all. Nor have I implemented
try_lock semantics yet, but that wouldn't be too hard. I have, however,
implemented upgradeable locks.

The implementation is basic, and uses the "gating" idea --- only one thread
can be "active pending" at any one time. Once that thread is locked, it
allows another thread to become active pending. This allows for fair access,
so no threads become starved. It uses Mutexes, so is quite heavyweight. I'll
see what I can do to improve the performance.

testrw.cpp is based on Howard's test code at
http://home.twcny.rr.com/hinnant/cpp_extensions/rw_perf.html

Anthony

-- 
Anthony Williams
Software Developer
Just Software Solutions Ltd
http://www.justsoftwaresolutions.co.uk





Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk