Thread-Safe的static data member初始化方法
2019-08-03 16:43
1121 查看
原文链接:https://www.geek-share.com/detail/2356332860.html
对于static data member的initialization,如果是在multi-threading的环境下,可以采用如下方法初始化:
1 if (s_data == null)
2 {
3 lock (s_dummy) // here s_dummy cannot be null
4 {
5 if (s_data == null)
6 {
7 // initialize s_data here
8 }
9 }
10 }
11
这样做的好处是既不影响performance,又能确保thread-safe。
1 if (s_data == null)
2 {
3 lock (s_dummy) // here s_dummy cannot be null
4 {
5 if (s_data == null)
6 {
7 // initialize s_data here
8 }
9 }
10 }
11
这样做的好处是既不影响performance,又能确保thread-safe。
转载于:https://www.cnblogs.com/kevinwan/archive/2006/04/18/378027.html
相关文章推荐
- Thread-Safe的static data member初始化方法
- C++ | static const integral data member在类中的初始化
- how to initialize Static data member in C++ (怎样初始化类的static数据成员)
- js data日期初始化的方法
- 7 面向对象(成员变量和局部变量的区别,类作为形式参数的问题,匿名对象,封装,private关键字,this关键字,构造方法,类的初始化过程,static关键字)
- js data日期初始化的5种方法 [转]
- 静态页面间数据传递方法总结--Data transforming between static html pages
- vue:页面初始化之前data之间的数据相互调用的方法
- Thread.SetData 方法
- 初始化mysql数据库提示缺少Data:dumper模块解决方法
- static方法,属性,代码块初始化顺序和执行顺序
- c++静态成员函数与线程同步(static member functions and thread-safety)
- StaticCodeDemo.java:29: 错误: 方法声明无效; 需要返回类型 person(){//给对应的对象进行针对性的初始化。
- 类中静态变量未定义导致undefined reference to static class member问题的解决方法
- js data日期初始化的5种方法
- static data member in a class
- warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
- 提示"illegal reference to data member'CPMAgentManageDlg::m_matrixMatrixSt'in a static member function"
- js data日期初始化的五种方法
- C++类中各种不同类型成员根据是否static 、是否const类型的初始化方法不尽相同,写代码时经常搞乱,网上搜了一下资料,全部总结一下。一、例子 [cpp] view plaincopy ---