samedi 1 septembre 2018

Why notify_one/notify_all is out from lock while pthread_cond_signal/pthread_cond_broadcast is in the lock?

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