0

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?

2 Answers 2

1

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, ...).

Sign up to request clarification or add additional context in comments.

2 Comments

What would a typical implementation do and why?
@usr Don't know, probably check if there are already more threads currently running (or doing significant work) than there are actual cores or something like this.
1

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.