|
|
От: |
Кодт
|
|
| Дата: | 15.03.17 17:40 | ||
| Оценка: | 10 (1) | ||
AG>The completions
AG>of the destructors for all initialized objects with thread storage duration within that thread are sequenced
AG>before the initiation of the destructors of any object with static storage duration.
#include <iostream>
using namespace std;
int g_tab = 1;
struct X {
int tab;
const char* name;
X(const char* name) : name(name), tab(g_tab++) {
cout << string(tab, '\t') << name << " : ctor" << endl;
}
~X() {
cout << string(tab, '\t') << name << " : dtor" << endl; }
};
X g1("g1");
thread_local X t1("t1");
thread_local X t2("t2");
X g2("g2");
int main() {
cout << "start!" << endl;
static X s1("s1");
cout << "test " << t1.name << endl; // первое обращение к TLS провоцирует инициализацию всех TLS-объектов
static X s2("s2");
cout << "finish!" << endl;
} g1 : ctor
g2 : ctor
start!
s1 : ctor
t1 : ctor
t2 : ctor
test t1
s2 : ctor
finish!
t2 : dtor
t1 : dtor
s2 : dtor
s1 : dtor
g2 : dtor
g1 : dtor
Перекуём баги на фичи!