Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-10-24 18:03:47


Chris Thomasson wrote:
> "Anthony Williams" <anthony_w.geo_at_[hidden]> wrote in message
> news:zmbl66cr.fsf_at_yahoo.com...
>> "Chris Thomasson" <cristom_at_[hidden]> writes:
>>> "Anthony Williams" <anthony_w.geo_at_[hidden]> wrote in message
>>> news:d58h7nlv.fsf_at_yahoo.com...
>
> [...]
>
>> If, when the first writer unlocks, the readers compete with the
>> waiting writer, then most of the time some readers will get in
>> before the writer re-registers that it's waiting, and blocks the
>> rest. You could just unblock
>> one thread, and if it's a reader then it unblocks all
>> currently-waiting readers. Rather like a condition variable
>> broadcast....
>
> I could adjust the logic of my algorithm so that it behaves exactly
> like that...

I implemented a variation of your algorithm that has

- active reader count
- pending/active writer bit (+semaphore)
- blocked reader+writer count (+semaphore)

The last active reader unblocks the pending writer, if there is one, else
the rest; the writer unblocks the rest on unlock ("thundering herd").
However I'm getting worse performance out of it compared to my other
prototype on a dual core Pentium D on Windows. I also tried to separate the
blocked readers and blocked writers and only unblock one writer at a time.
No change in performance. Maybe I've made a mistake somewhere. :-)


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