vendredi 10 décembre 2021

Is c++ std::future::wait() always cache-safe? [duplicate]

Is c++ std::future<>.wait() always cache-safe?

int x = 0;
std::future<void> fut = std::async( std::launch::async,
                                    [&]() { x = 1; } );

fut.wait();
std::cout << x;

In VS2019, wait() is implemented using a mutex. Therefore, the above snipped should be cache-safe. Am I right?

How is it on other platforms?

Maybe the same question, but not identically: Do std::promise::set_value() and std::future::wait() provide a memory fence?

Aucun commentaire:

Enregistrer un commentaire