I don't believe the CAS can fail because by the time lockWrite terminates, only the thread that executed that call should be able to modify the word. If that wasn't the case then that means that another thread would have entered or exited the region which means that lockWrite should not have terminated. This is what academics call a proof by contradiction.

A corollary to our previous lemma (yes I'm fancy being an academic today), if we're the only thread that can modify the word then unlockWrite's CAS should never fail because there's no contention. In fact, it shouldn't even need a CAS and a simple write should do the trick. QED.

Now for the moment I'd keep the CAS and put the assert back. I'd also try to reproduce the assertion and write a couple of new tests if required. Currently I think the current crop of tests could use a test where you have n threads spamming lockWrite/unlockWrite non-stop with even more threads spamming enterWrite/exitWrite.

We can go over this in more details on monday.