Implementing boost::upgrade_mutex using only standard locks
I think it actually is valid.

Here's all of the possible states of the two mutexes.

/* u: unlocked, s: shared locked, g: upgrade locked, x: exclusive locked
   (state): of which upgrade_mutex state, the states are as this line
   (inter-state): in the middle of these transitions, the states might be as this line
                  Xab means the original state is of symbol X,
                      and the thread is doing the lock/unlock of a-&gt;b
   symbol xmutex smutex (state) (inter-state)
     A      u      u       u
     B      x      u             Aux Axu Aug Agu Agx Axg Axs Dgu Dgx Exu Exg Exs
     C      u      s       s     Cs
     D      x      s       g     Axs Bs Cux Cug Ds Dgu Dgx Exs
     E      x      x       x
*/



The 10 lock/unlock methods all behave reasonably good in all of the states
Given the prior-method state is in the set, the during-/post-method state is in the set