lundi 30 juillet 2018

Locking mutex before using std::condition_variable

I have a question related to std::condition_variable. I read a lot about it and all examples shown locked mutex before using std::condition_variable like that:

std::unique_lock<std::mutex> lock(mutex);
condition_variable.wait(lock);
//...

or like that:

std::unique_lock<std::mutex> lock(mutex);
condition_variable.notify_one();
//...

Is it necessery to lock mutex before using condition variable or is it thread-safe?

Aucun commentaire:

Enregistrer un commentaire