Open cxlove opened 8 years ago
Using C++11 style: http://stackoverflow.com/questions/1008019/c-singleton-design-pattern 用new的话,不是线程安全的。
@Justme0 thanks for your reminding. the c++ code just for practicing, I will update it soon. Thanks
Ref: http://stackoverflow.com/questions/1008019/c-singleton-design-pattern
we used a static variable in a static function. it's thread safety in c++11, you can check it in http://stackoverflow.com/questions/1661529/is-meyers-implementation-of-singleton-pattern-thread-safe.
about the static variable's lift time, you can check it in http://stackoverflow.com/questions/246564/what-is-the-lifetime-of-a-static-variable-in-a-c-function.
You'll find a discussion of how to implement a thread-safety singleton using c++ in this paper: http://www.aristeia.com/Papers/DDJ%5FJul%5FAug%5F2004%5Frevised.pdf
RT