Tasks, Futures, and Promises

Learn about tasks, futures, and promises in C++.

Tasks are one of the latest additions to the C++11 standard. They offer better abstraction than threads. In most cases, they should be our first choice.

Press + to interact
 Tasks as data channels
Tasks as data channels

Tasks behave like data channels. On one side, the sender sets a value. On the other side, the receiver picks up the value. The sender is called promise, and the receiver is called future. Or, to say it a different way, the sender promises to provide a value that the receiver can pick up in the future.

The sender can provide value for more than one future. Besides a value, the sender can also provide a notification or an exception. They get calls about the future blocks. It means when future calls wait, they must wait until the promise puts the value into the channel.

Tasks are available in ...