From the course: Modern C++: Advanced Techniques and Features

Unlock this course with a free trial

Join today to access over 25,600 courses taught by industry experts.

Calling functions asynchronously

Calling functions asynchronously - C++ Tutorial

From the course: Modern C++: Advanced Techniques and Features

Calling functions asynchronously

- In this section we're going to see how to call functions asynchronously and how to control or to monitor the execution of those functions. So we are going to look at, for example, a function that we call that would like to return a value. We can see how to get the result of that function at some later point in the future. Okay, so in the standard library there's a function called std async defined in the future header file. And you invoke this function, you invoke std async and you basically tell it what function you'd like to call asynchronously and also any parameters you'd like to pass in. It then gives you back a future object, std future, and you can use the std future to monitor progress. Okay, so you call std async, you give it the name of the function or lambda. If the function takes any parameters or if the lambda takes any parameters, you can pass them in here. There's a very addict argument list. You can pass in whatever arguments you want to into that function and std…

Contents