From the course: Parallel and Concurrent Programming with C++ Part 2

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Download images

Solution: Download images - C++ Tutorial

From the course: Parallel and Concurrent Programming with C++ Part 2

Start my 1-month free trial

Solution: Download images

(upbeat music) - [Instructor] For our solution to the download images challenge we considered each call to the download image helper function as separate tasks that we could run asynchronously. And since we would need to get the return value with the number of bytes from each of those tasks, it seemed like the perfect use case for futures. So, we create a list on line 26 to hold our futures, then use a for loop to start a bunch of asynchronous tasks to execute the download image function for each image, and store the resulting future object in the list. After that, a second for loop on line 30, iterates through the list of futures using the get function to retrieve their return values and then adding them to the total bytes accumulator variable. Finally, when all of the futures are complete and their individual results added together, the function will return the total number of bytes downloaded on line 34. Scrolling…

Contents