mercredi 25 décembre 2019

Create a std::thread object in thread A, join in thread B

Is it allowed to call join() on a std::thread object that was created in a different thread, given that the object is properly synchronized between threads?

For example:

void cleanup(std::thread t)
{
    t.join();
}

int main()
{
    std::thread t{[] { /* something */ }};

    std::thread c{cleanup, std::move(t)};
    c.join();
}

Aucun commentaire:

Enregistrer un commentaire