From Jason Turner

[basic.start.dynamic]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpbiweyvwa/{from.md → to.md} +111 -0
tmp/tmpbiweyvwa/{from.md → to.md} RENAMED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Dynamic initialization of non-local variables <a id="basic.start.dynamic">[[basic.start.dynamic]]</a>
2
+
3
+ Dynamic initialization of a non-local variable with static storage
4
+ duration is unordered if the variable is an implicitly or explicitly
5
+ instantiated specialization, is partially-ordered if the variable is an
6
+ inline variable that is not an implicitly or explicitly instantiated
7
+ specialization, and otherwise is ordered.
8
+
9
+ [*Note 1*: An explicitly specialized non-inline static data member or
10
+ variable template specialization has ordered
11
+ initialization. — *end note*]
12
+
13
+ Dynamic initialization of non-local variables `V` and `W` with static
14
+ storage duration are ordered as follows:
15
+
16
+ - If `V` and `W` have ordered initialization and `V` is defined before
17
+ `W` within a single translation unit, the initialization of `V` is
18
+ sequenced before the initialization of `W`.
19
+ - If `V` has partially-ordered initialization, `W` does not have
20
+ unordered initialization, and `V` is defined before `W` in every
21
+ translation unit in which `W` is defined, then
22
+ - if the program starts a thread ([[intro.multithread]]) other than
23
+ the main thread ([[basic.start.main]]), the initialization of `V`
24
+ strongly happens before the initialization of `W`;
25
+ - otherwise, the initialization of `V` is sequenced before the
26
+ initialization of `W`.
27
+ - Otherwise, if the program starts a thread other than the main thread
28
+ before either `V` or `W` is initialized, it is unspecified in which
29
+ threads the initializations of `V` and `W` occur; the initializations
30
+ are unsequenced if they occur in the same thread.
31
+ - Otherwise, the initializations of `V` and `W` are indeterminately
32
+ sequenced.
33
+
34
+ [*Note 2*: This definition permits initialization of a sequence of
35
+ ordered variables concurrently with another sequence. — *end note*]
36
+
37
+ A *non-initialization odr-use* is an odr-use ([[basic.def.odr]]) not
38
+ caused directly or indirectly by the initialization of a non-local
39
+ static or thread storage duration variable.
40
+
41
+ It is *implementation-defined* whether the dynamic initialization of a
42
+ non-local non-inline variable with static storage duration is sequenced
43
+ before the first statement of `main` or is deferred. If it is deferred,
44
+ it strongly happens before any non-initialization odr-use of any
45
+ non-inline function or non-inline variable defined in the same
46
+ translation unit as the variable to be initialized. [^11] It is
47
+ *implementation-defined* in which threads and at which points in the
48
+ program such deferred dynamic initialization occurs.
49
+
50
+ [*Note 3*: Such points should be chosen in a way that allows the
51
+ programmer to avoid deadlocks. — *end note*]
52
+
53
+ [*Example 1*:
54
+
55
+ ``` cpp
56
+ // - File 1 -
57
+ #include "a.h"
58
+ #include "b.h"
59
+ B b;
60
+ A::A(){
61
+ b.Use();
62
+ }
63
+
64
+ // - File 2 -
65
+ #include "a.h"
66
+ A a;
67
+
68
+ // - File 3 -
69
+ #include "a.h"
70
+ #include "b.h"
71
+ extern A a;
72
+ extern B b;
73
+
74
+ int main() {
75
+ a.Use();
76
+ b.Use();
77
+ }
78
+ ```
79
+
80
+ It is *implementation-defined* whether either `a` or `b` is initialized
81
+ before `main` is entered or whether the initializations are delayed
82
+ until `a` is first odr-used in `main`. In particular, if `a` is
83
+ initialized before `main` is entered, it is not guaranteed that `b` will
84
+ be initialized before it is odr-used by the initialization of `a`, that
85
+ is, before `A::A` is called. If, however, `a` is initialized at some
86
+ point after the first statement of `main`, `b` will be initialized prior
87
+ to its use in `A::A`.
88
+
89
+ — *end example*]
90
+
91
+ It is *implementation-defined* whether the dynamic initialization of a
92
+ non-local inline variable with static storage duration is sequenced
93
+ before the first statement of `main` or is deferred. If it is deferred,
94
+ it strongly happens before any non-initialization odr-use of that
95
+ variable. It is *implementation-defined* in which threads and at which
96
+ points in the program such deferred dynamic initialization occurs.
97
+
98
+ It is *implementation-defined* whether the dynamic initialization of a
99
+ non-local non-inline variable with thread storage duration is sequenced
100
+ before the first statement of the initial function of a thread or is
101
+ deferred. If it is deferred, the initialization associated with the
102
+ entity for thread *t* is sequenced before the first non-initialization
103
+ odr-use by *t* of any non-inline variable with thread storage duration
104
+ defined in the same translation unit as the variable to be initialized.
105
+ It is *implementation-defined* in which threads and at which points in
106
+ the program such deferred dynamic initialization occurs.
107
+
108
+ If the initialization of a non-local variable with static or thread
109
+ storage duration exits via an exception, `std::terminate` is called (
110
+ [[except.terminate]]).
111
+