Title
std::async should be marked as [[nodiscard]]
Status
resolved
Section
[futures.async]
Submitter
Andrey Davydov

Created on 2017-01-20.00:00:00 last changed 83 months ago

Messages

Date: 2018-01-22.19:05:33

Proposed resolution:

Resolved by adoption of P0600 in Albuquerque

Date: 2017-03-15.00:00:00

[ 2017-03-04, Kona ]

This should be handled by Nico's paper P0600.

Date: 2017-01-27.00:00:00

[ 2017-01-27 Telecon ]

Priority 2; Nico to provide wording.

Date: 2017-01-20.00:00:00

Because the destructor of the std::future returned from the std::async blocks until the asynchronous operation completes, discarding the std::async return value leads to the synchronous code execution, which is pointless. For example, in the following code

void task1();
void task2();

void foo()
{
  std::async(std::launch::async,  task1),
  std::async(std::launch::async,  task2);
}

void bar()
{
  std::async(std::launch::async,  task1);
  std::async(std::launch::async,  task2);
}

task1 and task2 will be concurrently executed in the function 'foo', but sequentially in the function 'bar'.

History
Date User Action Args
2018-01-22 19:05:33adminsetmessages: + msg9617
2018-01-22 19:05:33adminsetstatus: new -> resolved
2017-03-14 03:14:09adminsetmessages: + msg9108
2017-01-30 15:36:02adminsetmessages: + msg8832
2017-01-20 00:00:00admincreate