https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106772

--- Comment #13 from Mkkt Bkkt <valera.mironow at gmail dot com> ---
example of simple mutex pseudocode that don't need call notify every unlock:
Same possible for other cases, if it doesn't please share example for me

```
int kUnlocked = 0;
int kLocked = 1;
int kLockedWithWaiters = 2;

std::atomic<int> state{0};

lock:
  // some spin
  if (state.cas(kUnlocked, kLocked)) {
    return;
  }
  do {
    if (state == kLockedWithWaiters || state.cas(kLocked, kLockedWithWaiters))
{
      state.wait(kLockedWithWaiters);
    }
  } while (!state.cas(kUnlocked, kLockedWithWaiters));

unlock:
  if (state.exchange(kUnlocked) == kLockedWithWaiters) {
    state.notify_one();
  }
```

Reply via email to