考虑在c ++中如何存在这两个存储持续时间(等等): 静态存储持续时间和线程存储持续时间。 。
接下来考虑这个代码:
static MyClassA a; thread_local static MyClassB b;另外假设“a”和“b”可能不在同一个编译单元中。 我相信“b”的析构函数将在“a”之前调用,因为线程存储持续时间将首先终止,并且只有在完成后,静态存储持续时间才会终止并调用“a”的析构函数。 我一直在寻找一个标准的参考,但我一直无法找到一个。 有人可以用权威来源特别证实这一点吗?
Consider how in c++ there are these two storage duration (among others): static storage duration and thread storage duration..
Next consider this code:
static MyClassA a; thread_local static MyClassB b;Additional pretend that "a" and "b" might not be in the same compilation unit. I "believe" that the destructor of "b" will be called before "a" as the thread storage duration will terminate first and only after that is complete will the static storage duration terminate and call the destructor of "a". I've been looking for a standard reference to this but I have been unable to find one. Can someone confirm this specifically with an authoritative source?
最满意答案
[basic.start.term] / P1:
对于在给定线程中线程存储持续时间的初始化对象的析构函数,将作为从该线程的初始函数返回并由于该线程调用std::exit调用的结果。 在具有静态存储持续时间的任何对象的析构函数启动之前,对该线程中具有线程存储持续时间的所有初始化对象的析构函数的完成都被排序。
[basic.start.term]/p1:
c ++静态vs线程存储时间的破坏顺序(c++ static vs thread storage duration destruction order)Destructors for initialized objects with thread storage duration within a given thread are called as a result of returning from the initial function of that thread and as a result of that thread calling std::exit. The completions of the destructors for all initialized objects with thread storage duration within that thread are sequenced before the initiation of the destructors of any object with static storage duration.
考虑在c ++中如何存在这两个存储持续时间(等等): 静态存储持续时间和线程存储持续时间。 。
接下来考虑这个代码:
static MyClassA a; thread_local static MyClassB b;另外假设“a”和“b”可能不在同一个编译单元中。 我相信“b”的析构函数将在“a”之前调用,因为线程存储持续时间将首先终止,并且只有在完成后,静态存储持续时间才会终止并调用“a”的析构函数。 我一直在寻找一个标准的参考,但我一直无法找到一个。 有人可以用权威来源特别证实这一点吗?
Consider how in c++ there are these two storage duration (among others): static storage duration and thread storage duration..
Next consider this code:
static MyClassA a; thread_local static MyClassB b;Additional pretend that "a" and "b" might not be in the same compilation unit. I "believe" that the destructor of "b" will be called before "a" as the thread storage duration will terminate first and only after that is complete will the static storage duration terminate and call the destructor of "a". I've been looking for a standard reference to this but I have been unable to find one. Can someone confirm this specifically with an authoritative source?
最满意答案
[basic.start.term] / P1:
对于在给定线程中线程存储持续时间的初始化对象的析构函数,将作为从该线程的初始函数返回并由于该线程调用std::exit调用的结果。 在具有静态存储持续时间的任何对象的析构函数启动之前,对该线程中具有线程存储持续时间的所有初始化对象的析构函数的完成都被排序。
[basic.start.term]/p1:
Destructors for initialized objects with thread storage duration within a given thread are called as a result of returning from the initial function of that thread and as a result of that thread calling std::exit. The completions of the destructors for all initialized objects with thread storage duration within that thread are sequenced before the initiation of the destructors of any object with static storage duration.
发布评论