Title
Unclear order of initialization of static and thread-local variables
Status
review
Section
6.9.3.2 [basic.start.static]
Submitter
Brian Bi

Created on 2024-06-20.00:00:00 last changed 3 months ago

Messages

Date: 2024-08-20.21:00:34

Suggested resolution:

  1. Change in 6.9.3.2 [basic.start.static] paragraph 1 as follows:

    Variables with static storage duration are initialized as a consequence of program initiation. Variables with thread storage duration are initialized as a consequence of thread execution. If the program does not start a thread (6.9.2 [intro.multithread]) other than the main thread (6.9.3.1 [basic.start.main]) before the completion of all non-deferred (6.9.3.3 [basic.start.dynamic]) initialization of non-block variables with static storage duration, then all non-deferred initialization (if any) of non-block variables with static storage duration strongly happens before any non-deferred initialization of non-block variables with thread storage duration. Within each of these phases of initiation, initialization occurs as follows.
  2. Change in 6.9.3.3 [basic.start.dynamic] paragraph 5 as follows:

    It is implementation-defined whether the dynamic initialization of a non-block non-inline variable o with static storage duration is sequenced before the first statement of main or is deferred. If it is deferred, it strongly happens before any non-initialization odr-use of any non-inline function or non-inline variable defined in the same translation unit as the variable to be initialized o and any deferred initialiation of non-inline non-block variables with thread storage duration defined in the same translation unit as o. [ Footnote: ... ] It is implementation-defined in which threads and at which points in the program such deferred dynamic initialization occurs.
Date: 2024-06-20.00:00:00

(From submission #559.)

Specification is missing that clarifies that non-local variables with static storage duration are initialized before those with thread storage duration.

History
Date User Action Args
2024-08-20 21:00:58adminsetstatus: open -> review
2024-07-28 08:59:27adminsetmessages: + msg7772
2024-06-20 00:00:00admincreate