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

Concurrency tasks

The concurrency support module supports a concept called task. A task is work that happens concurrently across threads. A concurrent task can be created using the packaged_task class. The packaged_task class conveniently connects the thread function, the corresponding promise, and feature objects.

Let's understand the use of packaged_task with a simple example. The following program gives us an opportunity to taste a bit of functional programming with lambda expressions and functions:

#include <iostream>#include <future>#include <promise>#include <thread>#include <functional>using namespace std;int main ( ) {     packaged_task<int (int, int)>        addTask ( [] ( int firstInput, int secondInput ) { return firstInput + secondInput; ...
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