Reputation: 850
From website cppreference.com , I learn that: "If both the std::launch::async and std::launch::deferred flags are set in policy, it is up to the implementation whether to perform asynchronous execution or lazy evaluation."
How to understand 'the implementation whether to perform asynchronous execution or lazy evaluation'.And if i set flag for both of them, then, is this execute in a new thread or deferred execute in local thread?
Upvotes: 0
Views: 905
Reputation: 76438
If you use both std::launch::async
and std::launch::deferred
you are telling the implementation that you don't care which one it uses. If you do care, don't say that you don't. Pick the one that you want.
Upvotes: 1
Reputation: 45948
How to understand 'the implementation whether to perform asynchronous execution or lazy evaluation'.
Well, exactly like it is stated. When both flags are set, the implementation decides itself if it starts the computation in a new/different thread (corresponding to std::launch::async
) or if it uses lazy evaluation (corresponding to std::launch::deferred
). The latter means it won't run any computation until you query the returned future, using std::future::get
, std::future::wait
and friends, which will cause the computation to be performed in the "local" thread.
And if i set flag for both of them, then, is this execute in a new thread or deferred execute in local thread?
As said above in this case it's up to the implementation to decide what to do and it can be different each time you call std::async(std::launch::async | std::launch::deferred, ...)
.
Upvotes: 1