mercredi 1 mai 2019

Will calling thread see modifications to local variables after thread.join()?

In the simplest possible example, let's say I have a function that starts a thread, which sets the value of a local variable to true. We join the thread, then leave the function.

bool func() {
    bool b = false;
    std::thread t([&]() { b = true; }); 
    t.join();
    return b;
}

Will this function return true, or is the behavior undefined?

Aucun commentaire:

Enregistrer un commentaire