vendredi 15 novembre 2019

Why can deadlock occur in this code snippet

Is deadlock possible in the following code snippet:

void f()
{
    {
        std::lock_guard <std::mutex> inner (lock1);
        // do something
    }
    std::lock_guard <std::mutex> outer (lock2);
    // do something
}

IOW, if multiple threads call this function, can a deadlock occur?

I am not too sure so any help would be highly appreciated.

Aucun commentaire:

Enregistrer un commentaire