Programming Languages — Technical specification for C++ extensions for concurrency

Since the extensions described in this ISO/IEC TS 19571:2016 are experimental and not part of the C++ standard library, they should not be declared directly within namespace std. Unless otherwise specified, all components described in this technical specification either: - modify an existing interface in the C++ Standard Library in-place, - are declared in a namespace whose name appends ::experimental::concurrency_v1 to a namespace defined in the C++ Standard Library, such as std, or - are declared in a subnamespace of a namespace described in the previous bullet, whose name is not the same as an existing subnamespace of namespace std. Each header described in this ISO/IEC TS 19571:2016 shall import the contents of std::experimental::concurrency_v1 into std::experimental as if by namespace std { namespace experimental { inline namespace concurrency_v1 {} } }

Langages de programmation — Spécification technique pour C ++ Extensions pour la concurrence

General Information

Status
Withdrawn
Publication Date
18-Jan-2016
Withdrawal Date
18-Jan-2016
Current Stage
9599 - Withdrawal of International Standard
Completion Date
25-Aug-2021
Ref Project

Buy Standard

Technical specification
ISO/IEC TS 19571:2016 - Programming Languages -- Technical specification for C++ extensions for concurrency
English language
19 pages
sale 15% off
Preview
sale 15% off
Preview
Technical specification
ISO/IEC TS 19571:2016 - Programming Languages -- Technical specification for C++ extensions for concurrency
English language
19 pages
sale 15% off
Preview
sale 15% off
Preview

Standards Content (Sample)

TECHNICAL ISO/IEC TS
SPECIFICATION 19571
First edition
2016-02-01
Programming Languages —
Technical Specification for C++
Extensions for Concurrency
Langages de programmation — Spécification technique pour C ++
Extensions pour la concurrence
Reference number
ISO/IEC TS 19571:2016(E)
©
ISO/IEC 2016

---------------------- Page: 1 ----------------------
ISO/IEC TS 19571:2016(E)

COPYRIGHT PROTECTED DOCUMENT
© ISO/IEC 2016, Published in Switzerland
All rights reserved. Unless otherwise specified, no part of this publication may be reproduced or utilized otherwise in any form
or by any means, electronic or mechanical, including photocopying, or posting on the internet or an intranet, without prior
written permission. Permission can be requested from either ISO at the address below or ISO’s member body in the country of
the requester.
ISO copyright office
Ch. de Blandonnet 8 • CP 401
CH-1214 Vernier, Geneva, Switzerland
Tel. +41 22 749 01 11
Fax +41 22 749 09 47
copyright@iso.org
www.iso.org
ii © ISO/IEC 2016 – All rights reserved

---------------------- Page: 2 ----------------------
ISO/IEC TS 19571:2016(E)
Contents
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . v
1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 Namespaces, headers, and modifications to standard classes . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Future plans (Informative) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Feature-testing recommendations (Informative) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 Improvements to std::future and Related APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.3 Class template future . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.4 Class template shared_future . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.5 Class template promise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.6 Class template packaged_task . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.7 Function template when_all . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.8 Class template when_any_result . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.9 Function template when_any . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.10 Function template make_ready_future . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.11 Function template make_exceptional_future . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3 Latches and Barriers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.2 Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.3 Latches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.4 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.5 Class latch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.6 Barrier types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.7 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.8 Class barrier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.9 Class flex_barrier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4 Atomic Smart Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.2 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.3 Class template atomic_shared_ptr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
4.4 Class template atomic_weak_ptr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
© ISO/IEC 2016 — All rights reserved iii

---------------------- Page: 3 ----------------------
ISO/IEC TS 19571:2016(E)
Foreword
ISO (the International Organization for Standardization) is a worldwide federation of national standards bodies (ISO
member bodies). The work of preparing International Standards is normally carried out through ISO technical
committees. Each member body interested in a subject for which a technical committee has been established has the right
to be represented on that committee. International organizations, governmental and non-governmental, in liaison with
ISO, also take part in the work. ISO collaborates closely with the International Electrotechnical Commission (IEC) on all
matters of electrotechnical standardization.
The procedures used to develop this document and those intended for its further maintenance are described in the ISO/
IEC Directives, Part 1. In particular the different approval criteria needed for the different types of ISO documents should
be noted. This document was drafted in accordance with the editorial rules of the ISO/IEC Directives, Part 2.
www.iso.org/directives
Attention is drawn to the possibility that some of the elements of this document may be the subject of patent rights. ISO
shall not be held responsible for identifying any or all such patent rights. Details of any patent rights identified during the
development of the document will be in the Introduction and/or on the ISO list of patent declarations received.
www.iso.org/patents
Any trade name used in this document is information given for the convenience of users and does not constitute an
endorsement.
For an explanation on the meaning of ISO specific terms and expressions related to conformity assessment, as well as
information about ISO's adherence to the WTO principles in the Technical Barriers to Trade (TBT) see the following
URL: Foreword - Supplementary information
The committee responsible for this document is ISO/IEC JTC1.
iv © ISO/IEC 2016 — All rights reserved

---------------------- Page: 4 ----------------------
TECHNICAL SPECIFICATION ISO/IEC TS 19571:2016(E)
Programming Languages — Technical Specification for C++
Extensions for Concurrency
1 General [general]
1.1 Namespaces, headers, and modifications to standard classes [general.namespaces]
1
Since the extensions described in this technical specification are experimental and not part of the C++ standard library,
they should not be declared directly within namespace std. Unless otherwise specified, all components described in this
technical specification either:
— modify an existing interface in the C++ Standard Library in-place,
— are declared in a namespace whose name appends ::experimental::concurrency_v1 to a namespace defined
in the C++ Standard Library, such as std, or
— are declared in a subnamespace of a namespace described in the previous bullet, whose name is not the same as
2
an existing subnamespace of namespace std.
Each header described in this technical specification shall import the contents of std::experimental::concurrency_v1
into std::experimental as if by
namespace std {
namespace experimental {
inline namespace concurrency_v1 {}
}
3
}
Unless otherwise specified, references to other entities described in this technical specification are assumed to be
qualified with std::experimental::concurrency_v1::, and references to entities described in the standard are assumed
4
to be qualified with std::.
Extensions that are expected to eventually be added to an existing header are provided inside the
header, which shall include the standard contents of as if by
5
#include
New headers are also provided in the directory, but without such an #include.
Table 1 — C++ library headers


1.2 Future plans (Informative) [general.plans]
1
This section describes tentative plans for future versions of this technical specification and plans for moving content into
2
future versions of the C++ Standard.
The C++ committee intends to release a new version of this technical specification approximately every year, containing
the library extensions we hope to add to a near-future version of the C++ Standard. Future versions will define their
contents in std::experimental::concurrency_v2, std::experimental::concurrency_v3, etc., with the most recent
3
implemented version inlined into std::experimental.
When an extension defined in this or a future version of this technical specification represents enough existing practice, it
will be moved into the next version of the C++ Standard by removing the experimental::concurrency_vN segment of its
namespace and by removing the experimental/ prefix from its header's path.
© ISO/IEC 2016 — All rights reserved 1

---------------------- Page: 5 ----------------------
ISO/IEC TS 19571:2016(E)
1.3 Feature-testing recommendations (Informative) [general.feature.test]
1
For the sake of improved portability between partial implementations of various C++ standards, WG21 (the ISO technical
committee for the C++ programming language) recommends that implementers and programmers follow the guidelines in
this section concerning feature-test macros. [ Note: WG21's SD-6 makes similar recommendations for the C++ Standard
itself. — end note ]
2
Implementers who provide a new standard feature should define a macro with the recommended name, in the same
circumstances under which the feature is available (for example, taking into account relevant command-line options), to
indicate the presence of support for that feature. Implementers should define that macro with the value specified in the
most recent version of this technical specification that they have implemented. The recommended macro name is
"__cpp_lib_experimental_" followed by the string in the "Macro Name Suffix" column.
3
Programmers who wish to determine whether a feature is available in an implementation should base that determination
on the presence of the header (determined with __has_include(

)) and the state of the macro with the
recommended name. (The absence of a tested feature may result in a program with decreased functionality, or the relevant
functionality may be provided in a different way. A program that strictly depends on support for a feature can just try to
use the feature unconditionally; presumably, on an implementation lacking necessary support, translation will fail.)
Table 2 — Significant features in this technical specification
Doc. Primary
Title Macro Name Suffix Value Header
No. Section
Improvements to std::future
N4399 2 future_continuations 201505
and Related APIs
N4204 C++ Latches and Barriers 3 latch 201505
N4204 C++ Latches and Barriers 3 barrier 201505
N4260 Atomic Smart Pointers 4 atomic_smart_pointers 201505
2 © ISO/IEC 2016 — All rights reserved

---------------------- Page: 6 ----------------------
ISO/IEC TS 19571:2016(E)

2 Improvements to std::future and Related APIs [futures]
2.1 General [futures.general]
1
The extensions proposed here are an evolution of the functionality of std::future and std::shared_future. The
extensions enable wait-free composition of asynchronous operations. Class templates std::promise and
std::packaged_task are also updated to be compatible with the updated std::future.
2.2 Header synopsis [header.future.synop]
#include
namespace std {
namespace experimental {
inline namespace concurrency_v1 {
template class promise;
template class promise;
template <> class promise;
template
void swap(promise& x, promise& y) noexcept;
template class future;
template class future;
template <> class future;
template class shared_future;
template class shared_future;
template <> class shared_future;
template class packaged_task; // undefined
template
class packaged_task;
template
void swap(packaged_task&, packaged_task&) noexcept;
template
see below make_ready_future(T&& value);
future make_ready_future();
template
future make_exceptional_future(exception_ptr ex);
template
future make_exceptional_future(E ex);
template
see below when_all(InputIterator first, InputIterator last);
template
© ISO/IEC 2016 — All rights reserved 3

---------------------- Page: 7 ----------------------
ISO/IEC TS 19571:2016(E)
see below when_all(Futures&&. futures);
template
struct when_any_result;
template
see below when_any(InputIterator first, InputIterator last);
template
see below when_any(Futures&&. futures);
} // namespace concurrency_v1
} // namespace experimental
template
struct uses_allocator, Alloc>;
template
struct uses_allocator, Alloc>;
} // namespace std
2.3 Class template future [futures.unique_future]
1
The specifications of all declarations within this subclause 2.3 and its subclauses are the same as the corresponding
declarations, as specified in C++14 §30.6.6, unless explicitly specified otherwise.
namespace std {
namespace experimental {
inline namespace concurrency_v1 {
template
class future {
public:
future() noexcept;
future(future &&) noexcept;
future(const future&) = delete;
future(future>&&) noexcept;
~future();
future& operator=(const future&) = delete;
future& operator=(future&&) noexcept;
shared_future share();
// retrieving the value
see below get();
// functions to check state
bool valid() const noexcept;
bool is_ready() const;
void wait() const;
template
future_status wait_for(const chrono::duration& rel_time) const;
4 © ISO/IEC 2016 — All rights reserved

---------------------- Page: 8 ----------------------
ISO/IEC TS 19571:2016(E)
template
future_status wait_until(const chrono::time_point& abs_time) const;
// continuations
template
see below then(F&& func);
};
} // namespace concurrency_v1
} // namespace experimental
} // namespace std
2
future(future>&& rhs) noexcept;
3
Effects: Constructs a future object from the shared state referred to by rhs. The future becomes ready when one of
the following occurs:
— Both the rhs and rhs.get() are ready. The value or the exception from rhs.get() is stored in the
future's shared state.
— rhs is ready but rhs.get() is invalid. An exception of type std::future_error, with an error condition
of std::future_errc::broken_promise is stored in the future's shared state.
4
Postconditions:
— valid() == true.
— rhs.valid() == false.
5
The member function template then provides a mechanism for attaching a continuation to a future object, which will be
executed as specified below.
© ISO/IEC 2016 — All rights reserved 5

---------------------- Page: 9 ----------------------
ISO/IEC TS 19571:2016(E)
6
template
see below then(F&& func);
7
Requires: INVOKE(DECAY_COPY (std::forward(func)), std::move(*this)) shall be a valid expression.
8
Effects: The function creates a shared state that is associated with the returned future object. Additionally,
— When the object's shared state is ready, the continuation
INVOKE(DECAY_COPY(std::forward(func)), std::move(*this)) is called on an unspecified thread
of execution with the call to DECAY_COPY() being evaluated in the thread that called then.
— Any value returned from the continuation is stored as the result in the shared state of the resulting future.
Any exception propagated from the execution of the continuation is stored as the exceptional result in the
shared state of the resulting future.
9
Returns: When result_of_t(future)> is future, for some type R2, the function returns
future. Otherwise, the function returns future(future)>>. [ Note: The rule
above is referred to as implicit unwrapping. Without this rule, the return type of then taking a callable returning a
future would have been future>. This rule avoids such nested future objects. The type of f2 below
is future and not future>:
[ Example:
future f1 = g();
future f2 = f1.then([](future f) {
future f3 = h();
return f3;
});
— end example ]
— end note ]
10
Postconditions: valid() == false on the original future. valid() == true on the future returned from then.
[ Note: In case of implicit unwrapping, the validity of the future returned from func cannot be established until after
the completion of the continuation. If it is not valid, the resulting future becomes ready with an exception of type
std::future_error, with an error condition of std::future_errc::broken_promise. — end note ]
11
bool is_ready() const;
12
Returns: true if the shared state is ready, otherwise false.
2.4 Class template shared_future [futures.shared_future]
1
The specifications of all declarations within this subclause 2.4 and its subclauses are the same as the corresponding
declarations, as specified in C++14 §30.6.7, unless explicitly specified otherwise.
namespace std {
namespace experimental {
inline namespace concurrency_v1 {
template
class shared_future {
public:
shared_future() noexcept;
shared_future(const shared_future&) noexcept;
shared_future(future&&) noexcept;
shared_future(future>&& rhs) noexcept;
~shared_future();
6 © ISO/IEC 2016 — All rights reserved

---------------------- Page: 10 ----------------------
ISO/IEC TS 19571:2016(E)
shared_future& operator=(const shared_future&);
shared_future& operator=(shared_future&&) noexcept;
// retrieving the value
see below get();
// functions to check state
bool valid() const noexcept;
bool is_ready() const;
void wait() const;
template
future_status wait_for(const chrono::duration& rel_time) const;
template
future_status wait_until(const chrono::time_point& abs_time) const;
// continuations
template
see below then(F&& func) const;
};
} // namespace concurrency_v1
} // namespace experimental
} // namespace std
2
shared_future(future>&& rhs) noexcept;
3
Effects: Constructs a shared_future object from the shared state referred to by rhs. The shared_future becomes
ready when one of the following occurs:
— Both the rhs and rhs.get() are ready. The value or the exception from rhs.get() is stored in the
shared_future's shared state.
— rhs is ready but rhs.get() is invalid. The shared_future stores an exception of type
std::future_error, with an error condition of std::future_errc::broken_promise.
4
Postconditions:
— valid() == true.
— rhs.valid() == false.
5
The member function template then provides a mechanism for attaching a continuation to a shared_future object, which
will be executed as specified below.
© ISO/IEC 2016 — All rights reserved 7

---------------------- Page: 11 ----------------------
ISO/IEC TS 19571:2016(E)
6
template
see below then(F&& func) const;
7
Requires: INVOKE(DECAY_COPY (std::forward(func)), *this) shall be a valid expression.
8
Effects: The function creates a shared state that is associated with the returned future object. Additionally,
— When the object's shared state is ready, the continuation
INVOKE(DECAY_COPY(std::forward(func)), *this) is called on an unspecified thread of execution
with the call to DECAY_COPY() being evaluated in the thread that called then.
— Any value returned from the continuation is stored as the result in the shared state of the resulting future.
Any exception propagated from the execution of the continuation is stored as the exceptional result in the
shared state of the resulting future.
9
Returns: When result_of_t(const shared_future&)> is future, for some type R2, the function
returns future. Otherwise, the function returns future(const shared_future&)>>.
[ Note: This analogous to future. See the notes on the return type of future::then in 2.3. — end note ]
10
Postconditions: valid() == true on the original shared_future object. valid() == true on the future returned
from then.
11 bool is_ready() const;
12
Returns: true if the shared state is ready, otherwise false.
2.5 Class template promise [futures.promise]
1
The specifications of all declarations within this subclause 2.5 and its subclauses are the same as the corresponding
declarations, as specified in C++14 §30.6.5, unless explicitly specified otherwise.
2
The future returned by the function get_future is the one defined in the experimental namespace (2.3).
2.6 Class template packaged_task [futures.task]
1
The specifications of all declarations within this subclause 2.6 and its subclauses are the same as the corresponding
declarations, as specified in C++14 §30.6.9, unless explicitly specified otherwise.
2
The future returned by the function get_future is the one defined in the experimental namespace (2.3).
2.7 Function template when_all [futures.when_all]
1
The function template when_all creates a future object that becomes ready when all elements in a set of future and
shared_future objects become ready.
8 © ISO/IEC 2016 — All rights reserved

---------------------- Page: 12 ----------------------
ISO/IEC TS 19571:2016(E)
2
template
future::value_type>>
when_all(InputIterator first, InputIterator last);
template
future.>> when_all(Futures&&. futures);
3
Requires: All futures and shared_futures passed into when_all must be in a valid state (i.e. valid() == true).
4
Remarks:
— The first overload shall not participate in overload resolution unless
iterator_traits::value_type is future or shared_future for some type R.
— For the second overload, let D be decay_t, and let U be remove_reference_t for each F in
i i i i i
Futures. This function shall not participate in overload resolution unless for each i either D is a
i
shared_future or U is a future.
i i i
5
Effects:
— A new shared state containing a Sequence is created, where Sequence is a vector for the first overload and
a tuple for the second overload. A new future object that refers to that shared state is created and
returned from when_all.
— If the first overload is called with first == last, when_all returns a future with an empty vector that is
immediately ready.
— If the second overload is called with no arguments, when_all returns a future> that is
immediately ready.
— Otherwise, any futures are moved, and any shared_futures are copied into, correspondingly, futures or
shared_futures of Sequence in the shared state.
— The order of the objects in the shared state matches the order of the arguments supplied to when_all.
— Once all the futures and shared_futures supplied to the call to when_all are ready, the resulting future,
as well as the futures and shared_futures of the Sequence, are ready.

— The shared state of the future returned by when_all will not store an exception, but the shared states of
futures and shared_futures held in the shared state may.
6
Postconditions:
— For the returned future, valid() == true.
— For all input futures, valid() == false.
— For all input shared_futures, valid() == true.
7
Returns: A future object that becomes ready when all of the input futuresand shared_futures are ready.
2.8 Class template when_any_result [futures.when_any_result]
1
The library provides a template for storing the result of when_any.
template
struct when_any_result {
size_t index;
Sequence futures;
};
2.9 Function template when_any [futures.when_any]
1
The function template when_any creates a future object that becomes ready when at least one element in a set of future
and shared_future objects becomes ready.
© ISO/IEC 2016 — All rights reserved 9

---------------------- Page: 13 ----------------------
ISO/IEC TS 19571:2016(E)
2
template
future::value_type>>>
when_any(InputIterator first, InputIterator last);
template
future.>>> when_any(Futures&&. futures);
3
Requires: All futures and shared_futures passed into when_all must be in a valid state (i.e. valid() == true).
4
Remarks:
— The first overload shall not participate in overload resolution unless
iterator_traits::value_type is future or shared_future for some type R.
— For the second overload, let D be decay_t, and let U be remove_reference_t for each F in
i i i i i
Futures. This function shall not participate in overload resolution unless for each i either D is a
i
shared_future or U is a future.
i i i
5
Effects:
— A new shared state containing when_any_result is created, where Sequence is a vector for
the first overload and a tuple for the second overload. A new future object that refers to that shared state
is created and returned from when_any.
— If the first overload is called with first == last, when_any returns a future that is immediately ready.
The value of the index field of the when_any_result is static_cast(-1). The futures field is
an empty vector.
— If the second overload of is called with no arguments, when_any returns a future that is immediately
ready. The value of the index field of the when_any_result is static_cast(-1). The futures
field is tuple<>.
— Otherwise, any futures are moved, and any shared_futures are copied into, correspondingly, futures or
shared_futures of the futures member of when_any_result in the shared state.
— The order of the objects in the futures shared state matches the order of the arguments supplied to
when_any.
— Once at least one of the futures or shared_futures supplied to the call to when_any is ready, the resulting
future is ready. Given the result future f, f.get().index is the position of the ready future or
shared_future in the futures member of when_any_result in the shared state.
— The shared state of the future returned by when_all will not store an exception, but the shared states of
futures and shared_futures held in the shared state may.
6
Postconditions:
— For the returned future, valid() == true.
— For all input futures, valid() == false.
— For all input shared_futures, valid() == true.
7
Returns:
— A future object that becomes ready when any of the input futures and shared_futures are ready.
10 © ISO/IEC 2016 — All rights reserved

---------------------- Page: 14 ----------------------
ISO/IEC TS 19571:2016(E)
2.10 Function template make_ready_future [futures.make_ready_future]
1
template
future make_ready_future(T&& value);
future make_ready_future();
2
Let U be decay_t. Then V is X& if U equals reference_wrapper, otherwise V is U.
3
Effects: The function creates a shared state that is immediately ready and returns a future associated with that
shared state. For the first overload, the type of the shared state is V and the result is constructed from
std::forward(value). For the second overload, the type of the shared state is void.
4
Postconditions: For the returned future, valid() == true and is_ready() == true.
...

TECHNICAL ISO/IEC TS
SPECIFICATION 19571
First edition
Programming Languages —
Technical Specification for C++
Extensions for Concurrency
Titre manque
PROOF/ÉPREUVE
Reference number
ISO/IEC TS 19571:2015(E)
©
ISO/IEC 2015

---------------------- Page: 1 ----------------------
ISO/IEC TS 19571:2015(E)

COPYRIGHT PROTECTED DOCUMENT
© ISO/IEC 2015, Published in Switzerland
All rights reserved. Unless otherwise specified, no part of this publication may be reproduced or utilized otherwise in any form
or by any means, electronic or mechanical, including photocopying, or posting on the internet or an intranet, without prior
written permission. Permission can be requested from either ISO at the address below or ISO’s member body in the country of
the requester.
ISO copyright office
Ch. de Blandonnet 8 • CP 401
CH-1214 Vernier, Geneva, Switzerland
Tel. +41 22 749 01 11
Fax +41 22 749 09 47
copyright@iso.org
www.iso.org
ii © ISO/IEC 2015 – All rights reserved

---------------------- Page: 2 ----------------------
ISO/IEC 19571:2015
Contents
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.1 Namespaces, headers, and modifications to standard classes . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2 Future plans (Informative) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.3 Feature-testing recommendations (Informative) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2 Improvements to std::future and Related APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3 Class template future . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.4 Class template shared_future . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.5 Class template promise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.6 Class template packaged_task . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.7 Function template when_all . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.8 Class template when_any_result . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.9 Function template when_any . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.10 Function template make_ready_future . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.11 Function template make_exceptional_future . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3 Latches and Barriers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.2 Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.3 Latches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.4 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.5 Class latch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.6 Barrier types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.7 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.8 Class barrier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.9 Class flex_barrier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4 Atomic Smart Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.2 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.3 Class template atomic_shared_ptr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.4 Class template atomic_weak_ptr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
© ISO/IEC 2015 — All rights reserved 3

---------------------- Page: 3 ----------------------
ISO/IEC 19571:2015
Foreword
ISO (the International Organization for Standardization) is a worldwide federation of national standards bodies (ISO
member bodies). The work of preparing International Standards is normally carried out through ISO technical
committees. Each member body interested in a subject for which a technical committee has been established has the right
to be represented on that committee. International organizations, governmental and non-governmental, in liaison with
ISO, also take part in the work. ISO collaborates closely with the International Electrotechnical Commission (IEC) on all
matters of electrotechnical standardization.
The procedures used to develop this document and those intended for its further maintenance are described in the ISO/
IEC Directives, Part 1. In particular the different approval criteria needed for the different types of ISO documents should
be noted. This document was drafted in accordance with the editorial rules of the ISO/IEC Directives, Part 2.
www.iso.org/directives
Attention is drawn to the possibility that some of the elements of this document may be the subject of patent rights. ISO
shall not be held responsible for identifying any or all such patent rights. Details of any patent rights identified during the
development of the document will be in the Introduction and/or on the ISO list of patent declarations received.
www.iso.org/patents
Any trade name used in this document is information given for the convenience of users and does not constitute an
endorsement.
For an explanation on the meaning of ISO specific terms and expressions related to conformity assessment, as well as
information about ISO's adherence to the WTO principles in the Technical Barriers to Trade (TBT) see the following
URL: Foreword - Supplementary information
The committee responsible for this document is ISO/IEC JTC1.
4 © ISO/IEC 2015 — All rights reserved

---------------------- Page: 4 ----------------------
ISO/IEC 19571:2015
1 General [general]
1.1 Namespaces, headers, and modifications to standard classes [general.namespaces]
1
Since the extensions described in this technical specification are experimental and not part of the C++ standard library,
they should not be declared directly within namespace std. Unless otherwise specified, all components described in this
technical specification either:
— modify an existing interface in the C++ Standard Library in-place,
— are declared in a namespace whose name appends ::experimental::concurrency_v1 to a namespace defined
in the C++ Standard Library, such as std, or
— are declared in a subnamespace of a namespace described in the previous bullet, whose name is not the same as
an existing subnamespace of namespace std.
2
Each header described in this technical specification shall import the contents of std::experimental::concurrency_v1
into std::experimental as if by
namespace std {
namespace experimental {
inline namespace concurrency_v1 {}
}
}
3
Unless otherwise specified, references to other entities described in this technical specification are assumed to be
qualified with std::experimental::concurrency_v1::, and references to entities described in the standard are assumed
to be qualified with std::.
4
Extensions that are expected to eventually be added to an existing header are provided inside the
header, which shall include the standard contents of as if by
#include
5
New headers are also provided in the directory, but without such an #include.
Table 1 — C++ library headers


1.2 Future plans (Informative) [general.plans]
1
This section describes tentative plans for future versions of this technical specification and plans for moving content into
future versions of the C++ Standard.
2
The C++ committee intends to release a new version of this technical specification approximately every year, containing
the library extensions we hope to add to a near-future version of the C++ Standard. Future versions will define their
contents in std::experimental::concurrency_v2, std::experimental::concurrency_v3, etc., with the most recent
implemented version inlined into std::experimental.
3
When an extension defined in this or a future version of this technical specification represents enough existing practice, it
will be moved into the next version of the C++ Standard by removing the experimental::concurrency_vN segment of its
namespace and by removing the experimental/ prefix from its header's path.
© ISO/IEC 2015 — All rights reserved 5

---------------------- Page: 5 ----------------------
ISO/IEC 19571:2015
1.3 Feature-testing recommendations (Informative) [general.feature.test]
1
For the sake of improved portability between partial implementations of various C++ standards, WG21 (the ISO technical
committee for the C++ programming language) recommends that implementers and programmers follow the guidelines in
this section concerning feature-test macros. [ Note: WG21's SD-6 makes similar recommendations for the C++ Standard
itself. — end note ]
2
Implementers who provide a new standard feature should define a macro with the recommended name, in the same
circumstances under which the feature is available (for example, taking into account relevant command-line options), to
indicate the presence of support for that feature. Implementers should define that macro with the value specified in the
most recent version of this technical specification that they have implemented. The recommended macro name is
"__cpp_lib_experimental_" followed by the string in the "Macro Name Suffix" column.
3
Programmers who wish to determine whether a feature is available in an implementation should base that determination
on the presence of the header (determined with __has_include(

)) and the state of the macro with the
recommended name. (The absence of a tested feature may result in a program with decreased functionality, or the relevant
functionality may be provided in a different way. A program that strictly depends on support for a feature can just try to
use the feature unconditionally; presumably, on an implementation lacking necessary support, translation will fail.)
Table 2 — Significant features in this technical specification
Doc. Primary
Title Macro Name Suffix Value Header
No. Section
Improvements to std::future
N4399 2 future_continuations 201505
and Related APIs
N4204 C++ Latches and Barriers 3 latch 201505
N4204 C++ Latches and Barriers 3 barrier 201505
N4260 Atomic Smart Pointers 4 atomic_smart_pointers 201505
6 © ISO/IEC 2015 — All rights reserved

---------------------- Page: 6 ----------------------
ISO/IEC 19571:2015
2 Improvements to std::future and Related APIs [futures]
2.1 General [futures.general]
1
The extensions proposed here are an evolution of the functionality of std::future and std::shared_future. The
extensions enable wait-free composition of asynchronous operations. Class templates std::promise and
std::packaged_task are also updated to be compatible with the updated std::future.
2.2 Header synopsis [header.future.synop]
#include
namespace std {
namespace experimental {
inline namespace concurrency_v1 {
template class promise;
template class promise;
template <> class promise;
template
void swap(promise& x, promise& y) noexcept;
template class future;
template class future;
template <> class future;
template class shared_future;
template class shared_future;
template <> class shared_future;
template class packaged_task; // undefined
template
class packaged_task;
template
void swap(packaged_task&, packaged_task&) noexcept;
template
see below make_ready_future(T&& value);
future make_ready_future();
template
future make_exceptional_future(exception_ptr ex);
template
future make_exceptional_future(E ex);
template
see below when_all(InputIterator first, InputIterator last);
template
© ISO/IEC 2015 — All rights reserved 7

---------------------- Page: 7 ----------------------
ISO/IEC 19571:2015
see below when_all(Futures&&. futures);
template
struct when_any_result;
template
see below when_any(InputIterator first, InputIterator last);
template
see below when_any(Futures&&. futures);
} // namespace concurrency_v1
} // namespace experimental
template
struct uses_allocator, Alloc>;
template
struct uses_allocator, Alloc>;
} // namespace std
2.3 Class template future [futures.unique_future]
1
The specifications of all declarations within this subclause 2.3 and its subclauses are the same as the corresponding
declarations, as specified in C++14 §30.6.6, unless explicitly specified otherwise.
namespace std {
namespace experimental {
inline namespace concurrency_v1 {
template
class future {
public:
future() noexcept;
future(future &&) noexcept;
future(const future&) = delete;
future(future>&&) noexcept;
~future();
future& operator=(const future&) = delete;
future& operator=(future&&) noexcept;
shared_future share();
// retrieving the value
see below get();
// functions to check state
bool valid() const noexcept;
bool is_ready() const;
void wait() const;
template
future_status wait_for(const chrono::duration& rel_time) const;
8 © ISO/IEC 2015 — All rights reserved

---------------------- Page: 8 ----------------------
ISO/IEC 19571:2015
template
future_status wait_until(const chrono::time_point& abs_time) const;
// continuations
template
see below then(F&& func);
};
} // namespace concurrency_v1
} // namespace experimental
} // namespace std
2
future(future>&& rhs) noexcept;
3
Effects: Constructs a future object from the shared state referred to by rhs. The future becomes ready when one of
the following occurs:
— Both the rhs and rhs.get() are ready. The value or the exception from rhs.get() is stored in the
future's shared state.
— rhs is ready but rhs.get() is invalid. An exception of type std::future_error, with an error condition
of std::future_errc::broken_promise is stored in the future's shared state.
4
Postconditions:
— valid() == true.
— rhs.valid() == false.
5
The member function template then provides a mechanism for attaching a continuation to a future object, which will be
executed as specified below.
© ISO/IEC 2015 — All rights reserved 9

---------------------- Page: 9 ----------------------
ISO/IEC 19571:2015
6
template
see below then(F&& func);
7
Requires: INVOKE(DECAY_COPY (std::forward(func)), std::move(*this)) shall be a valid expression.
8
Effects: The function creates a shared state that is associated with the returned future object. Additionally,
— When the object's shared state is ready, the continuation
INVOKE(DECAY_COPY(std::forward(func)), std::move(*this)) is called on an unspecified thread
of execution with the call to DECAY_COPY() being evaluated in the thread that called then.
— Any value returned from the continuation is stored as the result in the shared state of the resulting future.
Any exception propagated from the execution of the continuation is stored as the exceptional result in the
shared state of the resulting future.
9
Returns: When result_of_t(future)> is future, for some type R2, the function returns
future. Otherwise, the function returns future(future)>>. [ Note: The rule
above is referred to as implicit unwrapping. Without this rule, the return type of then taking a callable returning a
future would have been future>. This rule avoids such nested future objects. The type of f2 below
is future and not future>:
[ Example:
future f1 = g();
future f2 = f1.then([](future f) {
future f3 = h();
return f3;
});
— end example ]
— end note ]
10
Postconditions: valid() == false on the original future. valid() == true on the future returned from then.
[ Note: In case of implicit unwrapping, the validity of the future returned from func cannot be established until after
the completion of the continuation. If it is not valid, the resulting future becomes ready with an exception of type
std::future_error, with an error condition of std::future_errc::broken_promise. — end note ]
11
bool is_ready() const;
12
Returns: true if the shared state is ready, otherwise false.
2.4 Class template shared_future [futures.shared_future]
1
The specifications of all declarations within this subclause 2.4 and its subclauses are the same as the corresponding
declarations, as specified in C++14 §30.6.7, unless explicitly specified otherwise.
namespace std {
namespace experimental {
inline namespace concurrency_v1 {
template
class shared_future {
public:
shared_future() noexcept;
shared_future(const shared_future&) noexcept;
shared_future(future&&) noexcept;
shared_future(future>&& rhs) noexcept;
~shared_future();
10 © ISO/IEC 2015 — All rights reserved

---------------------- Page: 10 ----------------------
ISO/IEC 19571:2015
shared_future& operator=(const shared_future&);
shared_future& operator=(shared_future&&) noexcept;
// retrieving the value
see below get();
// functions to check state
bool valid() const noexcept;
bool is_ready() const;
void wait() const;
template
future_status wait_for(const chrono::duration& rel_time) const;
template
future_status wait_until(const chrono::time_point& abs_time) const;
// continuations
template
see below then(F&& func) const;
};
} // namespace concurrency_v1
} // namespace experimental
} // namespace std
2
shared_future(future>&& rhs) noexcept;
3
Effects: Constructs a shared_future object from the shared state referred to by rhs. The shared_future becomes
ready when one of the following occurs:
— Both the rhs and rhs.get() are ready. The value or the exception from rhs.get() is stored in the
shared_future's shared state.
— rhs is ready but rhs.get() is invalid. The shared_future stores an exception of type
std::future_error, with an error condition of std::future_errc::broken_promise.
4
Postconditions:
— valid() == true.
— rhs.valid() == false.
5
The member function template then provides a mechanism for attaching a continuation to a shared_future object, which
will be executed as specified below.
© ISO/IEC 2015 — All rights reserved 11

---------------------- Page: 11 ----------------------
ISO/IEC 19571:2015
6
template
see below then(F&& func) const;
7
Requires: INVOKE(DECAY_COPY (std::forward(func)), *this) shall be a valid expression.
8
Effects: The function creates a shared state that is associated with the returned future object. Additionally,
— When the object's shared state is ready, the continuation
INVOKE(DECAY_COPY(std::forward(func)), *this) is called on an unspecified thread of execution
with the call to DECAY_COPY() being evaluated in the thread that called then.
— Any value returned from the continuation is stored as the result in the shared state of the resulting future.
Any exception propagated from the execution of the continuation is stored as the exceptional result in the
shared state of the resulting future.
9
Returns: When result_of_t(const shared_future&)> is future, for some type R2, the function
returns future. Otherwise, the function returns future(const shared_future&)>>.
[ Note: This analogous to future. See the notes on the return type of future::then in 2.3. — end note ]
10
Postconditions: valid() == true on the original shared_future object. valid() == true on the future returned
from then.
11 bool is_ready() const;
12
Returns: true if the shared state is ready, otherwise false.
2.5 Class template promise [futures.promise]
1
The specifications of all declarations within this subclause 2.5 and its subclauses are the same as the corresponding
declarations, as specified in C++14 §30.6.5, unless explicitly specified otherwise.
2
The future returned by the function get_future is the one defined in the experimental namespace (2.3).
2.6 Class template packaged_task [futures.task]
1
The specifications of all declarations within this subclause 2.6 and its subclauses are the same as the corresponding
declarations, as specified in C++14 §30.6.9, unless explicitly specified otherwise.
2
The future returned by the function get_future is the one defined in the experimental namespace (2.3).
2.7 Function template when_all [futures.when_all]
1
The function template when_all creates a future object that becomes ready when all elements in a set of future and
shared_future objects become ready.
12 © ISO/IEC 2015 — All rights reserved

---------------------- Page: 12 ----------------------
ISO/IEC 19571:2015
2
template
future::value_type>>
when_all(InputIterator first, InputIterator last);
template
future.>> when_all(Futures&&. futures);
3
Requires: All futures and shared_futures passed into when_all must be in a valid state (i.e. valid() == true).
4
Remarks:
— The first overload shall not participate in overload resolution unless
iterator_traits::value_type is future or shared_future for some type R.
— For the second overload, let D be decay_t, and let U be remove_reference_t for each F in
i i i i i
Futures. This function shall not participate in overload resolution unless for each i either D is a
i
shared_future or U is a future.
i i i
5
Effects:
— A new shared state containing a Sequence is created, where Sequence is a vector for the first overload and
a tuple for the second overload. A new future object that refers to that shared state is created and
returned from when_all.
— If the first overload is called with first == last, when_all returns a future with an empty vector that is
immediately ready.
— If the second overload is called with no arguments, when_all returns a future> that is
immediately ready.
— Otherwise, any futures are moved, and any shared_futures are copied into, correspondingly, futures or
shared_futures of Sequence in the shared state.
— The order of the objects in the shared state matches the order of the arguments supplied to when_all.
— Once all the futures and shared_futures supplied to the call to when_all are ready, the resulting future,
as well as the futures and shared_futures of the Sequence, are ready.

— The shared state of the future returned by when_all will not store an exception, but the shared states of
futures and shared_futures held in the shared state may.
6
Postconditions:
— For the returned future, valid() == true.
— For all input futures, valid() == false.
— For all input shared_futures, valid() == true.
7
Returns: A future object that becomes ready when all of the input futuresand shared_futures are ready.
2.8 Class template when_any_result [futures.when_any_result]
1
The library provides a template for storing the result of when_any.
template
struct when_any_result {
size_t index;
Sequence futures;
};
2.9 Function template when_any [futures.when_any]
1
The function template when_any creates a future object that becomes ready when at least one element in a set of future
and shared_future objects becomes ready.
© ISO/IEC 2015 — All rights reserved 13

---------------------- Page: 13 ----------------------
ISO/IEC 19571:2015
2
template
future::value_type>>>
when_any(InputIterator first, InputIterator last);
template
future.>>> when_any(Futures&&. futures);
3
Requires: All futures and shared_futures passed into when_all must be in a valid state (i.e. valid() == true).
4
Remarks:
— The first overload shall not participate in overload resolution unless
iterator_traits::value_type is future or shared_future for some type R.
— For the second overload, let D be decay_t, and let U be remove_reference_t for each F in
i i i i i
Futures. This function shall not participate in overload resolution unless for each i either D is a
i
shared_future or U is a future.
i i i
5
Effects:
— A new shared state containing when_any_result is created, where Sequence is a vector for
the first overload and a tuple for the second overload. A new future object that refers to that shared state
is created and returned from when_any.
— If the first overload is called with first == last, when_any returns a future that is immediately ready.
The value of the index field of the when_any_result is static_cast(-1). The futures field is
an empty vector.
— If the second overload of is called with no arguments, when_any returns a future that is immediately
ready. The value of the index field of the when_any_result is static_cast(-1). The futures
field is tuple<>.
— Otherwise, any futures are moved, and any shared_futures are copied into, correspondingly, futures or
shared_futures of the futures member of when_any_result in the shared state.
— The order of the objects in the futures shared state matches the order of the arguments supplied to
when_any.
— Once at least one of the futures or shared_futures supplied to the call to when_any is ready, the resulting
future is ready. Given the result future f, f.get().index is the position of the ready future or
shared_future in the futures member of when_any_result in the shared state.
— The shared state of the future returned by when_all will not store an exception, but the shared states of
futures and shared_futures held in the shared state may.
6
Postconditions:
— For the returned future, valid() == true.
— For all input futures, valid() == false.
— For all input shared_futures, valid() == true.
7
Returns:
— A future object that becomes ready when any of the input futures and shared_futures are ready.
14 © ISO/IEC 2015 — All rights reserved

---------------------- Page: 14 ----------------------
ISO/IEC 19571:2015
2.10 Function template make_ready_future [futures.make_ready_future]
1
template
future make_ready_future(T&& value);
future make_ready_future();
2
Let U be decay_t. Then V is X& if U equals reference_wrapper, otherwise V is U.
3
Effects: The function creates a shared state that is immediately ready and returns a future associated with that
shared state. For the first overload, the type of the shared state is V and the result is constructed from
std::forward(value). For the second overload, the type of the shared state is void.
4
Postconditions: For the returned future, valid() == true and is_ready() == true.
2.11 Function template make_exceptional_future [futures.make_exceptional_future]
1 template
future make_exceptional_future(exception_ptr ex);
2
Effects: Equivalent to
promise p;
p.set_exception(ex);
return p.get_future();
3
template
fut
...

Questions, Comments and Discussion

Ask us and Technical Secretary will try to provide an answer. You can facilitate discussion about the standard in here.