Skip to Content
C++ Reactive Programming
book

C++ Reactive Programming

by Praseed Pai, Peter Abraham
June 2018
Intermediate to advanced
348 pages
8h 45m
English
Packt Publishing
Content preview from C++ Reactive Programming

std::packaged_task

Now, let's discuss how we get a return value associated with a future into your code that needs results. The std::packaged_task is a template class that is available in the standard library to achieve task-based parallelism with the help of futures and promises. By setting up futures and promises in threads, it simplifies setting up a task without any explicit locks for sharing the result. A packaged_task instance provides a wrapper over std::thread to put the return value or exception caught into a promise. The member function get_future() in std::packaged_task will give you the future instance associated with the corresponding promise. Let's look at an example that uses a packaged task to find the sum of all elements ...

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

Functional Programming in C++

Functional Programming in C++

Ivan Cukic

Publisher Resources

ISBN: 9781788629775Supplemental Content