Reputation: 1449
I create a promise and future objects:
Promise<int> p = promise<int>();
Future<int> f = p.get_future();
I pass the promise to the background thread, which eventually calls p.set_value(myInt)
.
In the main thread, I call f.get()
.
What if f.get()
is called after p.set_value(myInt)
is called?
Would f.get()
immediately return myInt
?
Upvotes: 3
Views: 497
Reputation: 10972
According to the documentation it calls wait - in order to wait for a result. According to that description in turn, it is stated that:
Blocks until the result becomes available.
That seems to imply it should not block (even for a short while) if there is a result already. So except for some sanity checks, mutex handling or the like I would assume it to return immediately as per the description.
Do you have an actual issue or are you merely asking ?
Upvotes: 3