本文介绍了C ++静态与线程存储持续时间销毁顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑一下在c ++中这两个存储持续时间如何(以及其他):静态存储持续时间和线程存储持续时间..

Consider how in c++ there are these two storage duration (among others): static storage duration and thread storage duration..

接下来考虑以下代码:

static MyClassA a;
thread_local static MyClassB b;

还假装"a"和"b"可能不在同一编译单元中.我相信"将在"a"之前调用析构函数"b",因为线程存储持续时间将首先终止,并且只有在线程存储持续时间完成后,静态存储持续时间才会终止并调用"a"的析构函数.我一直在寻找对此的标准参考,但一直找不到.有人可以通过权威消息来源专门确认这一点吗?

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:

[basic.start.term]/p1:

这篇关于C ++静态与线程存储持续时间销毁顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 06:24