GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||
GeezerVison is showing cplusplus.com — std::async Reference
<future>
function template
<future>
std::async
Call function asynchronously
The value returned by fn can be accessed through the future object returned (by calling its member future::get). The second version (2) lets the caller select a specific launching policy, while the first version (1) uses automatic selection, as if calling (2) with launch::async|launch::deferred as policy.The function temporarily stores in the shared state either the threading handler used or decay copies of fn and args (as a deferred function) without making it ready. Once the execution of fn is completed, the shared state contains the value returned by fn and is made ready. Parameters
Fn and Args... are template parameters: if implicitly deduced, these are the proper lvalue or rvalue reference types of the arguments. Note though, that the function uses decay copies of fn and args... (see std::ref for a wrapper class that makes references copyable).Return valueA future object whose shared state is made ready when the execution of fn ends. The value retrieved by its member future::get is the value returned by fn (if any).When launch::async is selected, the future returned is linked to the end of the thread created, even if its shared state is never accessed: in this case, its destructor synchronizes with the return of fn. Therefore, the return value shall not be disregarded for asynchronous behavior, even when fn returns void.result_of::type is the type returned by Fn when called with arguments of the types in Args. Example
Possible output (the first two lines may be in a different order, or scrambled):
Data racesThe arguments are accessed to create decay copies.All visible side effects are synchronized between the call to async and the call to fn, and between its return point and the access to the returned future's share state. Exception safetyBasic guarantee: if an exception is thrown, all objects involved are left in a valid state.This member function throws an exception on the following conditions:
If fn throws an exception, it is caught and stored in the shared state accessed by the returned future. See also
Home page | Privacy policy
© cplusplus.com, 2000-2026 - All rights reserved - v3.3.4s Spotted an error? contact us | |||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |