10 Aug
2010
10 Aug
'10
3:05 p.m.
On 08/10/2010 04:28 PM, Stefan Strasser wrote:
isn't that a waste? Why make reader 3 and 4 waiting and then make those running before the writer? The code to reproduce that is at the end.
I don't think Boost.Thread specifies this behaviour, so it is probably platform-dependent. I'm guessing readers 3 and 4 have to wait because the writer thread requested an exclusive lock (and otherwise the writer thread would be starved), but once all locks have been released it is a decision of the OS scheduler which thread is then woken up first and can acquire a lock - one of the reader threads in this case apparently.
Right, if you want an "order preserving shared mutex", you have to write it yourself.