From the course: C++ Development: Advanced Concepts, Lambda Expressions, and Best Practices
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
The async function - C++ Tutorial
From the course: C++ Development: Advanced Concepts, Lambda Expressions, and Best Practices
The async function
- [Instructor] The standard async function runs a thread asynchronously and returns a value using the standard future class. In this way, async operates much like standard thread, but allows return values. This is async.cpp from chapter six of the exercise files. You'll see we have a structure down here called prime time with two elements, a duration and account. You notice that the type of the duration is this seconds, secs, which is an alias up here for standard chrono duration of type double. So that's a duration object, a standard chrono duration object. And here we have an unsigned 64-bit integer type for the count. And we have a function called count primes that counts the number of primes between two and a maximum value. And it returns this prime time object with the count and the duration, how long it took to count those many primes. And down here in main, we make use of this. We have a couple of constants, a…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.