ARTICLE AD BOX
Have some multi-threaded code that needs to do some locking. The details of that do not matter here. But I do the canonical do { ... } while (!CAS) loop.
To keep the code concise I want to add a wait in the while condition.
Obviously the wait always returns true.
In the following code (godbolt link)
As far as I can tell the wait function does not get optimized out, even though it does not affect the while condition.
Is the wait() always guaranteed to run if the CAS fails, or should I rewrite the wait() function somehow to prevent the optimizer from eliminating it?
