2

A quote from N4713:

Dynamic initialization of non-local variables V and W with static storage duration are ordered as follows:
If V and W have ordered initialization and V is defined before W within a single translation unit, the initialization of V is sequenced before the initialization of W.

Is there a similar paragraph for variables of thread storage duration? In the code below, is the initialization of V sequenced before the initialization of W?

thread_local int V = 1; thread_local int W = V; 

Updated:

I want to modify the code as follows:

thread_local string V; thread_local string W; 

1 Answer 1

2

From 6.7.2 Thread storage duration [basic.stc.thread]:

A variable with thread storage duration shall be initialized before its first odr-use (6.2) and, if constructed, shall be destroyed on thread exit.

This means that V is initialized before `W'.

Sign up to request clarification or add additional context in comments.

1 Comment

What if there is no dependency and both need dynamic initialization?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.