Misleading example

The "Do something" and resetting of the mutex variable should be inside the if block.

Link to content: Beginning Rust Programming - Section 5

I can see where the example tries to go, it does it poorly though.

It muddles the idea of the mutex with its implemented use further down the page; that instead of “if 0 then 1, continue”, the author’s next block is instead “if not 0 abort”. (Course, it then also hides the logic of the lock/unlock behind the library function, making it opaque to the reader)

Yup, agreed. The shame is that it’s not actually a difficult concept to grasp, but I wonder if the poor/opaque example will lead to readers being more rather than less confused.