"is there a way to cancel/detach a future in c++11?" Code Answer

4

the c++11 standard does not provide a direct way to cancel a task started with std::async. you will have to implement your own cancellation mechanism, such as passing in an atomic flag variable to the async task which is periodically checked.

your code should not crash though. on reaching the end of main, the std::future<int> object held in result is destroyed, which will wait for the task to finish, and then discard the result, cleaning up any resources used.

By Coxy on September 20 2022

Answers related to “is there a way to cancel/detach a future in c++11?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.