当前位置:网站首页>thread_local 变量的析构顺序
thread_local 变量的析构顺序
2022-07-31 14:47:00 【maray】
#include <stdio.h>
class C1
{
public:
C1() {
printf("c1 cons\n"); }
~C1() {
printf("c1 des\n"); }
};
class C2
{
public:
C2() {
printf("c2 cons\n"); }
~C2() {
printf("c2 des\n"); }
};
int main(int argc, const char *argv[])
{
thread_local C1 c1;
thread_local C2 c2; // 预期 c2 后构造,先析构。因为语义上 c2 有可能依赖 c1(例如 c1 是 c2 的构造参数)
return 0;
}
输出:
[xiaochu.yh test]$g++ test.cpp --std=c++11
[xiaochu.yh test]$./a.out
c1 cons
c2 cons
c2 des
c1 des
边栏推荐
猜你喜欢
2021 OWASP TOP 10 Vulnerability Guide
海康摄像机取流RTSP地址规则说明
组合系列--有排列就有组合
QGIS 加载WMS数据,重新投影
OpenShift 4 - Customize RHACS security policies to prevent production clusters from using high-risk registry
乡村基冲刺港交所:5个月期内亏2224万 SIG与红杉中国是股东
OAuth2:微服务权限校验Session共享
The recently popular domestic interface artifact Apipost experience
2021 OWASP TOP 10 漏洞指南
格林美瑞交所IPO:募资3.8亿美元 更多中国企业将赴欧洲上市
随机推荐
自适应控制——仿真实验二 用Narendra方案设计模型参考自适应系统
【Pytorch】torch.argmax()用法
基于最小二乘法和SVM从天气预报中预测太阳能发电量(Matlab代码实现)
Getting started with UnityShader (3) - Unity's Shader
以后面试官问你 为啥不建议使用Select *,请你大声回答他!
MySQL [aggregate function]
Five dimensions to start MySQL optimization
Redis与分布式:哨兵模式
最近很火的国产接口神器Apipost体验
Nuget打包并上传教程
"Listen to me, thank you" can be said in ancient poetry?Tsinghua University has developed an artifact of "Searching Sentences According to Meaning", which can search for the famous sayings you want wi
【Pytorch】F.softmax()方法说明
Nuget打包并上传教程
Essential Learning for Getting Started with Unity Shader - Transparency Effect
NPM Taobao mirror (latest version) released a new version of npm mirror at 2021-11-21 16:53:52 [easy to understand]
OpenShift 4 - 定制 RHACS 安全策略,阻断生产集群使用高风险 Registry
Asynchronous processing business using CompletableFuture
Resnet&API
MySql总结
Shell project combat 1. System performance analysis