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

This Technical Specification will refer to the existing standard in ISO/IEC 14882:2020(E) and extend it with types and features related to concurrency

Langages de programmation — Spécification technique pour les extensions C++ de concurrency 2

General Information

Status
Not Published
Current Stage
5020 - FDIS ballot initiated: 2 months. Proof sent to secretariat
Start Date
13-Aug-2024
Completion Date
13-Aug-2024
Ref Project

Buy Standard

Draft
ISO/IEC DTS 9922 - Programming Languages — Technical specification for C++ extensions for concurrency 2 Released:30. 07. 2024
English language
19 pages
sale 15% off
Preview
sale 15% off
Preview

Standards Content (Sample)


FINAL DRAFT
Technical
Specification
ISO/IEC JTC 1/SC 22
Programming Languages —
Secretariat: ANSI
Technical specification for C++
Voting begins on:
extensions for concurrency 2
2024-08-13
Voting terminates on:
2024-10-08
RECIPIENTS OF THIS DRAFT ARE INVITED TO SUBMIT,
WITH THEIR COMMENTS, NOTIFICATION OF ANY
RELEVANT PATENT RIGHTS OF WHICH THEY ARE AWARE
AND TO PROVIDE SUPPOR TING DOCUMENTATION.
IN ADDITION TO THEIR EVALUATION AS
BEING ACCEPTABLE FOR INDUSTRIAL, TECHNO­
LOGICAL, COMMERCIAL AND USER PURPOSES, DRAFT
INTERNATIONAL STANDARDS MAY ON OCCASION HAVE
TO BE CONSIDERED IN THE LIGHT OF THEIR POTENTIAL
TO BECOME STAN DARDS TO WHICH REFERENCE MAY BE
MADE IN NATIONAL REGULATIONS.
Reference number
FINAL DRAFT
Technical
Specification
ISO/IEC JTC 1/SC 22
Programming Languages —
Secretariat: ANSI
Technical specification for C++
Voting begins on:
extensions for concurrency 2
Voting terminates on:
RECIPIENTS OF THIS DRAFT ARE INVITED TO SUBMIT,
WITH THEIR COMMENTS, NOTIFICATION OF ANY
RELEVANT PATENT RIGHTS OF WHICH THEY ARE AWARE
AND TO PROVIDE SUPPOR TING DOCUMENTATION.
© ISO/IEC 2024
IN ADDITION TO THEIR EVALUATION AS
All rights reserved. Unless otherwise specified, or required in the context of its implementation, no part of this publication may
BEING ACCEPTABLE FOR INDUSTRIAL, TECHNO­
LOGICAL, COMMERCIAL AND USER PURPOSES, DRAFT
be reproduced or utilized otherwise in any form or by any means, electronic or mechanical, including photocopying, or posting on
INTERNATIONAL STANDARDS MAY ON OCCASION HAVE
the internet or an intranet, without prior written permission. Permission can be requested from either ISO at the address below
TO BE CONSIDERED IN THE LIGHT OF THEIR POTENTIAL
or ISO’s member body in the country of the requester.
TO BECOME STAN DARDS TO WHICH REFERENCE MAY BE
MADE IN NATIONAL REGULATIONS.
ISO copyright office
CP 401 • Ch. de Blandonnet 8
CH-1214 Vernier, Geneva
Phone: +41 22 749 01 11
Email: copyright@iso.org
Website: www.iso.org
Published in Switzerland Reference number
© ISO/IEC 2024 – All rights reserved
ii
Contents
Foreword iv
1 Scope 1
2 Normative references 2
3 Terms and definitions 3
4 General 4
4.1 Implementation compliance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
4.2 Namespaces and headers and modifications to standard classes . . . . . . . . . . . . . . . 4
4.3 Feature-testing recommendations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
5 Synchronized Value 6
5.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
5.2 Header synopsis . . . . . . . . . . . . . . . . . . . . 6
5.3 Class template synchronized_value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
5.4 apply function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
6 Safe reclamation 8
6.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
6.2 Hazard pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
6.3 Read-copy update (RCU) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
7 Bytewise Atomic Memcpy 16
7.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
7.2 Header synopsis . . . . . . . . . . . . . . . . 16
7.3 atomic_load_per_byte_memcpy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
7.4 atomic_store_per_byte_memcpy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
8 Asymmetric Fence 17
8.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
8.2 Header synopsis . . . . . . . . . . . . . . . . . . . . . 17
8.3 asymmetric_thread_fence_heavy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
8.4 asymmetric_thread_fence_light . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
9 Order and consistency 19
Contents © ISO/IEC 2024 – All rights reserved iii

Foreword [foreword]
ISO (the International Organization for Standardization) and IEC (the International Electrotechnical
Commission) form the specialized system for worldwide standardization. National bodies that are members
of ISO or IEC participate in the development of International Standards through technical committees
established by the respective organization to deal with particular fields of technical activity. ISO and IEC
technical committees collaborate in fields of mutual interest. Other international organizations, governmental
and non-governmental, in liaison with ISO and IEC, also take part in the work.
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 document should be noted. This document was drafted in accordance with the editorial rules of the
ISO/IEC Directives, Part 2 (see www.iso.org/directives or www.iec.ch/members_experts/refdocs).
ISO and IEC draw attention to the possibility that the implementation of this document may involve the
use of (a) patent(s). ISO and IEC take no position concerning the evidence, validity or applicability of any
claimed patent rights in respect thereof. As of the date of publication of this document, ISO and IEC had not
received notice of (a) patent(s) which may be required to implement this document. However, implementers
are cautioned that this may not represent the latest information, which may be obtained from the patent
database available at www.iso.org/patents and https://patents.iec.ch. ISO and IEC shall not be held
responsible for identifying any or all such patent rights.
Any trade name used in this document is information given for the convenience of users and does not
constitute an endorsement.
For an explanation of the voluntary nature of standards, the meaning of ISO specific terms and expressions
related to conformity assessment, as well as information about ISO’s adherence to the World Trade Organiza-
tion (WTO) principles in the Technical Barriers to Trade (TBT) see www.iso.org/iso/foreword.html. In
the IEC, see www.iec.ch/understanding-standards.
This document was prepared by Joint Technical Committee ISO/IEC JTC 1, Information technology,
Subcommittee SC 22, Programming languages, their environments and system software interfaces.
Any feedback or questions on this document should be directed to the user’s national standards body. A com-
pletelistingofthesebodiescanbefoundatwww.iso.org/members.htmlandwww.iec.ch/national-committees.
Foreword © ISO/IEC 2024 – All rights reserved iv

1 Scope [scope]
This document builds upon ISO/IEC 14882 by describing requirements for implementations of an interface
that computer programs written in the C++ programming language could use to invoke algorithms with
concurrent execution. The algorithms described by this document are realizable across a broad class of
computer architectures. This document is written as a set of differences from the base standard.
Some of the functionality described by this document might be considered for standardization in a future
version of C++, but it is not currently part of ISO/IEC 14882:2020. Some of the functionality in this
document might never be standardized, and other functionality might be standardized in a substantially
different form.
The goal of this document is to build widespread existing practice for concurrency in the ISO/IEC 14882:2020
algorithms library. It gives advice on extensions to those vendors who wish to provide them.
Scope © ISO/IEC 2024 – All rights reserved 1

2 Normative references [refs]
The following documents are referred to in the text in such a way that some or all of their content constitutes
requirements of this document. For dated references, only the edition cited applies. For undated references,
the latest edition of the referenced document (including any amendments) applies.
— ISO/IEC 14882:2020, Programming Languages — C++
Normative references © ISO/IEC 2024 – All rights reserved 2

3 Terms and definitions [defs]
No terms and definitions are listed in this document. ISO and IEC maintain terminological databases for use
in standardization at the following addresses:
— IEC Electropedia: available at https://www.electropedia.org/
— ISO Online browsing platform: available at https://www.iso.org/obp
Terms and definitions © ISO/IEC 2024 – All rights reserved 3

4 General [general]
4.1 Implementation compliance [general.compliance]
Conformance requirements for this document are those defined in ISO/IEC 14882:2020, §4.1, as applied to a
merged document consisting of ISO/IEC 14882:2020 amended by this document.
NOTE Conformance is defined in terms of the behaviour of programs.
4.2 Namespaces and headers and modifications to standard classes
[general.namespaces]
Since the extensions described in this document are experimental and not part of the ISO/IEC 14882:2020
library, they are not declared directly within namespace std. Unless otherwise specified, all components
described in this document either:
— modify an existing interface in the ISO/IEC 14882:2020 library in-place,
— are declared in a namespace whose name appends ::experimental::concurrency_v2 to a namespace
defined in the ISO/IEC 14882:2020 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.
Whenever an unqualified name is used in the specification of a declaration D, its meaning is established in
accordance with (ISO/IEC 14882:2020, §4.1.2) by performing unqualified name lookup in the context of D.
NOTE 1 Argument-dependent lookup is not performed.
Similarly, the meaning of a qualified-id is established in accordance with performing qualified name lookup in
the context of D.
NOTE 2 Operators in expressions are not so constrained.
Table 1 shows the headers described in this document
Table 1 — C++ library headers





4.3 Feature-testing recommendations [general.feature.test]
An implementation that provides support for this document should define each feature test macro defined
in Table 2 and Table 3 if no associated headers are indicated for that macro, and if associated headers are
indicated for a macro, that macro is defined after inclusion of one of the corresponding headers specified in
Table 2 and Table 3.
Table 2 — Feature-test macros name
Title Subclause Macro name
Synchronized Value 5 __cpp_lib_experimental_synchronized_value
Hazard pointers 6.2 __cpp_lib_experimental_hazard_pointer
Read-copy update(RCU) 6.3 __cpp_lib_experimental_rcu
Bytewise atomic memcpy 7 __cpp_lib_experimental_bytewise_atomic_memcpy
Asymmetric Fence 8,33 __cpp_lib_experimental_asymmetric_fence
§ 4.3 © ISO/IEC 2024 – All rights reserved 4

Table 3 — Feature-test macros header
Title Value Header
Synchronized Value 202406
Hazard pointers 202406
Read-copy update(RCU) 202406
Bytewise atomic memcpy 202406
Asymmetric Fence 202406
§ 4.3 © ISO/IEC 2024 – All rights reserved 5

5 Synchronized Value [synchronizedvalue]
5.1 General [synchronizedvalue.general]
This clause describes a class template to provide locked access to a value in order to facilitate the construction
of race-free programs.
5.2 Header synopsis [synchronizedvalue.syn]
namespace std::experimental::inline concurrency_v2 {
template
class synchronized_value;
template
invoke_result_t apply(
F&& f,synchronized_value&. values);
}
5.3 Class template synchronized_value [synchronizedvalue.class]
namespace std::experimental::inline concurrency_v2 {
template
class synchronized_value
{
public:
synchronized_value(const synchronized_value&) = delete;
synchronized_value& operator=(const synchronized_value&) = delete;
template
synchronized_value(Args&&. args);
private:
T value; // exposition only
mutex mut; // exposition only
};
template
synchronized_value(T)
-> synchronized_value;
}
An object of type synchronized_value wraps an object of type T. The wrapped object can be accessed
by passing a callable object or function to apply. All such accesses are done with a lock held to ensure that
only one thread may be accessing the wrapped object for a given synchronized_value at a time.
template
synchronized_value(Args&&. args);
Constraints:
— (sizeof.(Args) != 1)istrueor(!same_as>
&&.) is true
— is_constructible_v is true
Effects: Direct-non-list-initializes value with std::forward(args).
Throws: Any exceptions emitted by the initialization of value.
system_error if any necessary resources cannot be acquired.
§ 5.3 © ISO/IEC 2024 – All rights reserved 6

5.4 apply function [synchronizedvalue.fn]
template
invoke_result_t apply(
F&& f,synchronized_value&. values);
Constraints: sizeof.(values) != 0 is true.
Effects: Equivalent to:
scoped_lock lock(values.mut.);
return invoke(std::forward(f),values.value.);
NOTE 1 It is not possible to pass a single instance of synchronized_value more than once to the same
invocation of apply.
EXAMPLE
synchronized_value sv;
void f(int,int);
apply(f,sv,sv); // undefined behaviour, sv passed more than once to same call
NOTE 2 The invocation of f cannot call apply directly or indirectly passing a
...

Questions, Comments and Discussion

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