13. Concurrency

Keep it simple:as simple as possible,but no simpler.

– A. Einstein

Introduction

Tasks and threads

Passing Arguments

Returning Results

Sharing Data

Waiting for Events

Communicating Tasks

future and promise; packaged_task; async()

Advice

13.1. Introduction

Concurrency – the execution of several tasks simultaneously – is widely used to improve throughput (by using several processors for a single computation) or to improve responsiveness (by allowing one part of a program to progress while another is waiting for a response). All modern programming languages provide support for this. The support provided by the C++ standard library is a portable and type-safe variant of what has been used in C++ for more than 20 years ...

Get A Tour of C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.