mercredi 13 novembre 2019

Is condition_variable.notify a synchronization point?

Let's say I have something like this:

bool signalled = false;
std::condition_variable cv;
void thread1() {
  while (true) {
    std::unique_lock l(mutex);
    cv.wait_until(l, [] { return signalled; });
    return;
  }
}

void thread2...N() {
  signalled = true;
  cv.notify_all();
}

Is that considered thread-safe? The boolean may be set to true in many threads to interrupt thread1.

Aucun commentaire:

Enregistrer un commentaire