On Tue, Mar 26, 2013 at 6:06 AM, Vicente J. Botet Escriba <vicente.botet@wanadoo.fr> wrote:
Le 24/03/13 18:24, Vicente J. Botet Escriba a écrit :
Le 18/03/13 00:06, Fredrik Orderud a écrit :
v2/shared_mutex indeed appears to be quite different. From what I can see, it lacks the exclusive_waiting_blocked field. This makes me question if it is capable of prioritizing write-lock request in favor of read-lock requests, as the pthread and win32 equivalents are doing. What are your thoughts on this?
I suspect that Howard Hinnant prefered a fair solution. 
After more deep insight I'm wondering if write_entered_ is not used to ensure priority for writers. Note that write_entered_ doesn't mean that the mutex is in exclusive mode but that some one has requested to be in.  The mutex is in exclusive mode when write_entered_ and n_readers_==0.

What do you think?
 
It appears like you have a point there Vicente. v2/shared_mutex does indeed seem to prioritize exclusive mode lock attempts through write_entered_. Sorry for not noticing that earlier.

I think it would be easier to understand v2 shared_mutex & upgrade_mutex if the implementation had been "cleaned up" a bit. Especially, the gate1_ & gate2_ can probably be given more informative names. Also, replacing all the bitmask-logic with bitfields would make the code easier to read.

Regards,
Fredrik