C++11 class similar to .Net's ManualResetEvent, but without the ability to "reset" The goal is to block all threads that call WaitOne(). When Set() is called, those threads continue. Any calls to WaitOne(), after Set(), return immediately. The challenge is to make sure that all calls to WaitOne() are either "before" or "after" the call to Set(), so that no threads see _state false, but miss the notify_all. I'm looking for feedback on performance and correctness.

#ifndef NO_RESET_EVENT_H
#define NO_RESET_EVENT_H

#include &lt;condition_variable&gt;
#include &lt;atomic&gt;

class NoResetEvent
{
public:
    NoResetEvent() : state(false) {}
    NoResetEvent(const NoResetEvent&amp; other) = delete;

    void WaitOne() {
        std::unique_lock&lt;std::mutex&gt; lock(sync);
        while (!state) {
            underlying.wait(lock);
        }
    }

    void Set() {
        std::unique_lock&lt;std::mutex&gt; lock(sync);
        state = true;
        underlying.notify_all();
    }

private:
    std::condition_variable underlying;
    std::mutex sync;
    volatile bool state;
};

#endif
Looks good.

The only thing I would change is:

volatile bool _state;


into

 std::atomic&lt;bool&gt;  _state;


The issue with volatile is that it does not universally provide that guarantee that updates are visible to all threads (which std::atomic does).

Could simplify the wait() call.

    while (!_state) {
        _underlying.wait(lock);
    }

    // could be:
    _underlying.wait(lock,[&amp;state](){return state;});


Personally I don't like prefix '_' on identifiers. The rules for using '_' as a prefix are complicated. Even if you know the rules not everybody that reads your code will.