Daily bit(e) of C++ | std::async
Daily bit(e) of C++ #157, The C++11 simple deferred execution utility: std::async.
The C++11 std::async is a simple tool for launching asynchronous tasks to either start a task in parallel or to defer execution on the same thread.
The benefit of std::async is simplicity, as std::async directly returns a std::future; however, we pay for that simplicity with a lack of control.
In my received email, there is a wrong code that I past it in the below:
```
// We can use async, to defer execution of code until the end of the scope
{
FILE *file = fopen("/dev/null", "r");
auto deferred_close = std::async(std::launch::deferred, [file](){
fclose(file);
});
} // destructor for deferred_close runs and closes the file
```
But it doesn't work, and we should call get() or wait() method for execution of lambda function.
do people really use it in production? for a test-scenario and quick and dirty async threading, it's nice but the lack of ctrl makes it less attractive for real production code. what do you think?