Do you know of standard implementation of async() that blocks on the future-destructor?
VS2015 seems to block in the future destructor of std::async, see the output from the below program: /M Output: policy: async 0ms (before) 3ms (async) 10008ms (after) ----- policy: deferred 0ms (before) 1ms (async) 10015ms (after) Snippet: { std::cout << print_time(begin) << " (before)" << std::endl; auto future = std::async([begin]() { std::cout << print_time(begin) << " (async)" << std::endl; std::this_thread::sleep_for(std::chrono::milliseconds(10000)); }); } std::cout << print_time(begin) << " (after)" << std::endl; On Mon, Oct 12, 2015 at 2:02 AM, Vicente J. Botet Escriba < vicente.botet@wanadoo.fr> wrote:
Hi,
all is in the title.
Best, Vicente
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
On 10/11/2015 9:02 PM, Vicente J. Botet Escriba wrote:
Hi,
all is in the title.
Don't they all? Blocking in the future destructor is what the standard mandates. Regards, -- Agustín K-ballo Bergé.- http://talesofcpp.fusionfenix.com
Le 12/10/15 15:57, Agustín K-ballo Bergé a écrit :
On 10/11/2015 9:02 PM, Vicente J. Botet Escriba wrote:
Hi,
all is in the title.
Don't they all? Blocking in the future destructor is what the standard mandates.
I'm confused. Do they block on the future destructor or the destructor of the shared state? The note of the standard says on the destructor of the returned future
"[ Note: If a future obtained from std::async is moved outside the local scope, other code that uses the future must be aware that the future’s destructor may block for the shared state to become ready. — end note ]"
C++ International Standard Vicente
On 10/12/2015 6:42 PM, Vicente J. Botet Escriba wrote:
Le 12/10/15 15:57, Agustín K-ballo Bergé a écrit :
On 10/11/2015 9:02 PM, Vicente J. Botet Escriba wrote:
Hi,
all is in the title.
Don't they all? Blocking in the future destructor is what the standard mandates.
I'm confused. Do they block on the future destructor or the destructor of the shared state?
They may block on the destructor of the shared state: 30.6.4 [futures.state]/5 When an asynchronous return object or an asynchronous provider is said to release its shared state, it means: - [...] - these actions will not block for the shared state to become ready, except that it may block if all of the following are true: the shared state was created by a call to `std::async`, the shared state is not yet ready, and this was the last reference to the shared state. You can think of `std::async` conceptually being implemented as having an `std::thread` within the shared state, which chooses to join on destruction to avoid termination.
The note of the standard says on the destructor of the returned future
"[ Note: If a future obtained from std::async is moved outside the local scope, other code that uses the future must be aware that the future’s destructor may block for the shared state to become ready. — end note ]"
Notes are not normative. A future's destructor is where you'd most likely notice the block, but it could happen during assignment too. Regards, -- Agustín K-ballo Bergé.- http://talesofcpp.fusionfenix.com
Le 13/10/15 00:04, Agustín K-ballo Bergé a écrit :
On 10/12/2015 6:42 PM, Vicente J. Botet Escriba wrote:
Le 12/10/15 15:57, Agustín K-ballo Bergé a écrit :
On 10/11/2015 9:02 PM, Vicente J. Botet Escriba wrote:
Hi,
all is in the title.
Don't they all? Blocking in the future destructor is what the standard mandates.
I'm confused. Do they block on the future destructor or the destructor of the shared state?
They may block on the destructor of the shared state:
30.6.4 [futures.state]/5 When an asynchronous return object or an asynchronous provider is said to release its shared state, it means: - [...] - these actions will not block for the shared state to become ready, except that it may block if all of the following are true: the shared state was created by a call to `std::async`, the shared state is not yet ready, and this was the last reference to the shared state.
You can think of `std::async` conceptually being implemented as having an `std::thread` within the shared state, which chooses to join on destruction to avoid termination.
The note of the standard says on the destructor of the returned future
"[ Note: If a future obtained from std::async is moved outside the local scope, other code that uses the future must be aware that the future’s destructor may block for the shared state to become ready. — end note ]"
Notes are not normative. A future's destructor is where you'd most likely notice the block, but it could happen during assignment too.
Thanks Agustin for clarifications, Vicente
participants (3)
-
Agustín K-ballo Bergé
-
Mikael Olenfalk
-
Vicente J. Botet Escriba