From Jason Turner

[algorithms.parallel.defns]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpfr5tbiis/{from.md → to.md} +39 -5
tmp/tmpfr5tbiis/{from.md → to.md} RENAMED
@@ -1,10 +1,13 @@
1
- ### Terms and definitions <a id="algorithms.parallel.defns">[[algorithms.parallel.defns]]</a>
2
 
3
- A *parallel algorithm* is a function template listed in this
4
- International Standard with a template parameter named
5
- `ExecutionPolicy`.
 
 
 
6
 
7
  Parallel algorithms access objects indirectly accessible via their
8
  arguments by invoking the following functions:
9
 
10
  - All operations of the categories of the iterators that the algorithm
@@ -12,11 +15,11 @@ arguments by invoking the following functions:
12
  - Operations on those sequence elements that are required by its
13
  specification.
14
  - User-provided function objects to be applied during the execution of
15
  the algorithm, if required by the specification.
16
  - Operations on those function objects required by the specification.
17
- \[*Note 1*: See  [[algorithms.general]]. — *end note*]
18
 
19
  These functions are herein called *element access functions*.
20
 
21
  [*Example 1*:
22
 
@@ -29,5 +32,36 @@ The `sort` function may invoke the following element access functions:
29
  preconditions specified in [[sort]]).
30
  - The user-provided `Compare` function object.
31
 
32
  — *end example*]
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Preamble <a id="algorithms.parallel.defns">[[algorithms.parallel.defns]]</a>
2
 
3
+ Subclause [[algorithms.parallel]] describes components that C++ programs
4
+ may use to perform operations on containers and other sequences in
5
+ parallel.
6
+
7
+ A *parallel algorithm* is a function template listed in this document
8
+ with a template parameter named `ExecutionPolicy`.
9
 
10
  Parallel algorithms access objects indirectly accessible via their
11
  arguments by invoking the following functions:
12
 
13
  - All operations of the categories of the iterators that the algorithm
 
15
  - Operations on those sequence elements that are required by its
16
  specification.
17
  - User-provided function objects to be applied during the execution of
18
  the algorithm, if required by the specification.
19
  - Operations on those function objects required by the specification.
20
+ \[*Note 1*: See  [[algorithms.requirements]]. — *end note*]
21
 
22
  These functions are herein called *element access functions*.
23
 
24
  [*Example 1*:
25
 
 
32
  preconditions specified in [[sort]]).
33
  - The user-provided `Compare` function object.
34
 
35
  — *end example*]
36
 
37
+ A standard library function is *vectorization-unsafe* if it is specified
38
+ to synchronize with another function invocation, or another function
39
+ invocation is specified to synchronize with it, and if it is not a
40
+ memory allocation or deallocation function.
41
+
42
+ [*Note 2*: Implementations must ensure that internal synchronization
43
+ inside standard library functions does not prevent forward progress when
44
+ those functions are executed by threads of execution with weakly
45
+ parallel forward progress guarantees. — *end note*]
46
+
47
+ [*Example 2*:
48
+
49
+ ``` cpp
50
+ int x = 0;
51
+ std::mutex m;
52
+ void f() {
53
+ int a[] = {1,2};
54
+ std::for_each(std::execution::par_unseq, std::begin(a), std::end(a), [&](int) {
55
+ std::lock_guard<mutex> guard(m); // incorrect: lock_guard constructor calls m.lock()
56
+ ++x;
57
+ });
58
+ }
59
+ ```
60
+
61
+ The above program may result in two consecutive calls to `m.lock()` on
62
+ the same thread of execution (which may deadlock), because the
63
+ applications of the function object are not guaranteed to run on
64
+ different threads of execution.
65
+
66
+ — *end example*]
67
+