Boost logo

Boost :

From: Anthony Williams (anthony_w.geo_at_[hidden])
Date: 2005-10-06 05:20:42


"Peter Dimov" <pdimov_at_[hidden]> writes:

> I have produced a read/write mutex implementation as a side effect,
> available at
>
> http://www.pdimov.com/cpp/rw_mutex.cpp
>
> that is lock-free when there is no contention (i.e. when a reader attempts a
> lock and no writers are active, or when a writer attempts a lock and the
> lock is free.)
>
> It appears to work (famous last words.) If you see any subtle problems or
> can stress test it on a multiprocessor, please let me know.

This implementation either starves writers or starves readers. Running your
test code lets the writers all do some work, then the readers take over until
they're all finished, then the writers alternate until they're all done.

Running my test harness against it (based on Howards sample at
http://home.twcny.rr.com/hinnant/cpp_extensions/rw_perf.html), I get lots of
writer work, followed by a little reader work, then more writer work, then a
little more reader work, such that all the writer threads finish considerably
before the reader threads.

This is a single CPU machine.

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