title: How std::atomic wait operation works?
body: <p>Starting C++20, <code>std::atomic</code> has <code>wait()</code> and <code>notify_one()</code>/<code>notify_all()</code> operations. But I didn't get exactly how they are supposed to work. <a href="https://en.cppreference.com/w/cpp/atomic/atomic/wait" rel="noreferrer">cppreference says</a>:</p>
  <blockquote>
  <p>Performs atomic waiting operations. Behaves as if it repeatedly
  performs the following steps:</p>
  <ul>
  <li>Compare the value representation of this-&gt;load(order) with that of old.
  <ul>
  <li>If those are <strong>equal</strong>, then blocks until <strong><code>*this</code> is notified by notify_one() or notify_all(), or the thread is unblocked spuriously.</strong></li>
  <li>Otherwise, returns.</li>
  </ul>
  </li>
  </ul>
  <p><strong>These functions are guaranteed to return only if value has changed,
  even if underlying implementation unblocks spuriously.</strong></p>
  </blockquote>
  <p>I don't exactly get how these 2 parts are related to each other. Does it mean that if the value if <strong>not changed</strong>, then the function does not return even if I use <code>notify_one()</code>/<code>notify_all()</code> method? meaning that the operation is somehow equal to following pseudocode?</p>
  <pre><code>while (*this == val) {
      // block thread
  }
  </code></pre>