samedi 29 octobre 2016

mutex locking order c++11

I have a (fairly easy) question about std::mutex in c++11:

Suppose 6 threads want to lock the same mutex using std::lock_guard. Thread 1 ask for the lock, after which, thread 2 does the same, etc, until all 6 of them asked for the lock. The first thread to get the lock will make the 5 other threads block until the lock is available for each of them.

Now does the 5 other threads will be receiving the lock in the order they asked for it? Even though they all asked for it, can we take for granted that thread 2 will be the next one to receive the lock, or one of the thread may starve?

Aucun commentaire:

Enregistrer un commentaire