Boost logo

Boost :

Subject: Re: [boost] [c++std-parallel-2020] Re: We need a coherent higher level parallelization story for C++ (was [thread] Is there a non-blocking future-destructor?)
From: Peter Dimov (pdimov_at_[hidden])
Date: 2015-10-14 12:47:51


Lawrence Crowl wrote:

> First, std::async and std::future have no flaws for what they were
> designed to do. They were designed to provide relatively easy parallelism
> for small core systems under the fork-join model.

I thought that it was well established by now that std::async isn't very
useful for fork-join (if at all.)

First, it's required to execute each (asynchronous) task as-if in a new
thread with respect to thread locals, which in practice means "in a new
thread".

Second, it has to allocate the future shared state.

These two non-flaws kill its performance for fork-join parallelism.

The first one is not related to its use of std::future, but the second one
is. Given an interface of the form

    X x;
    async_result<R> r;

    std::async( r, [&]{ return x.f(); } );

with async_result being non-copyable and non-movable and ~async_result
blocking on the async task, the task can store its result directly into r,
without needing to allocate.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk