Skip to Content
Mastering C++ Programming
book

Mastering C++ Programming

by Jeganathan Swaminathan
September 2017
Beginner to intermediate
384 pages
8h 4m
English
Packt Publishing
Content preview from Mastering C++ Programming

Using tasks with a thread support library

In the previous section, you learned how packaged_task can be used in an elegant way. I love lambda functions a lot. They look a lot like mathematics. But not everyone likes lambda functions as they degrade readability to some extent. Hence, it isn't mandatory to use lambda functions with a concurrent task if you don't prefer lambdas. In this section, you'll understand how to use a concurrent task with the thread support library, as shown in the following code:

#include <iostream>#include <future>#include <thread>#include <functional>using namespace std;int add ( int firstInput, int secondInput ) {  return firstInput + secondInput;}int main ( ) {  packaged_task<int (int, int)> addTask( add); future<int> ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Multi-Paradigm Programming with Modern C++

Multi-Paradigm Programming with Modern C++

Georgy Pashkov

Publisher Resources

ISBN: 9781786461629Supplemental Content