As per my understanding, notify_one/notify_all provide the similar behavior as pthread_cond_signal/pthread_cond_broadcast but why one( pthread_cond_signal) should be kept inside the lock while other( notify_one) is out ?
pthread_mutex_t m; mutex m;
pthread_cond_t c; condition_variable c;
pthread_mutex_lock(&m); { lock_guard<mutex> l(m);
// do some thing // do some thing } //mutex unlocked
pthread_cond_signal(&c); c.notify_one();
pthread_mutex_unlock(&m);
Aucun commentaire:
Enregistrer un commentaire