Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
Is there any guarantee regarding initialization of static and thread_local objects? In example, is there any guarantee about the value printed by the following program? #include<iostream> s...
#3: Post edited
- Is there any guarantee regarding initialization of static and thread_local objects? In example, is there any guarantee about the value printed by the following program?
- #include<iostream>
- static int a=3;
thread_local int b=a;- int main(void) {
- std::cout << b << std::endl;
- }
- For threads other than the 1st one surely thread_local objects will be initialized after statics(*). But does the C++ standard provide any guarantee that thread_local objects will be initialized after static objects for the 1st thread?
(*) Unless the thread is started from the constructor of a global/static object. But not going there.
- Is there any guarantee regarding initialization of static and thread_local objects? In example, is there any guarantee about the value printed by the following program?
- #include<iostream>
- static int a=3;
- []() int b=a;
- int main(void) {
- std::cout << b << std::endl;
- }
- For threads other than the 1st one surely thread_local objects will be initialized after statics(*). But does the C++ standard provide any guarantee that thread_local objects will be initialized after static objects for the 1st thread?
- (*) Unless the thread is started from the constructor of a global/static object. But not going there.
#2: Post edited
- Is there any guarantee regarding initialization of static and thread_local objects? In example, is there any guarantee about the value printed by the following program?
- #include<iostream>
- static int a=3;
- thread_local int b=a;
- int main(void) {
- std::cout << b << std::endl;
- }
- For threads other than the 1st one surely thread_local objects will be initialized after statics(*). But does the C++ standard provide any guarantee that thread_local objects will be initialized after static objects for the 1st thread?
(*) Unless the thread is started from the constructor of an static object. But not going there.
- Is there any guarantee regarding initialization of static and thread_local objects? In example, is there any guarantee about the value printed by the following program?
- #include<iostream>
- static int a=3;
- thread_local int b=a;
- int main(void) {
- std::cout << b << std::endl;
- }
- For threads other than the 1st one surely thread_local objects will be initialized after statics(*). But does the C++ standard provide any guarantee that thread_local objects will be initialized after static objects for the 1st thread?
- (*) Unless the thread is started from the constructor of a global/static object. But not going there.
#1: Initial revision
Static and thread_local initialization order
Is there any guarantee regarding initialization of static and thread_local objects? In example, is there any guarantee about the value printed by the following program? #include<iostream> static int a=3; thread_local int b=a; int main(void) { std::cout << b << std::endl; } For threads other than the 1st one surely thread_local objects will be initialized after statics(*). But does the C++ standard provide any guarantee that thread_local objects will be initialized after static objects for the 1st thread? (*) Unless the thread is started from the constructor of an static object. But not going there.