??????????????C++11??????????????????????DCL????????????£?
????1 atomic<Widget*> Widget::pInstance{ nullptr };
????2 Widget* Widget::Instance() {
????3     if (pInstance == nullptr) {
????4         lock_guard<mutex> lock{ mutW };
????5         if (pInstance == nullptr) {
????6             pInstance = new Widget();
????7         }
????8     }
????9     return pInstance;
????10 }
????C++11?е?atomic??????memory_order_seq_cst?????3??6?д?????????????????????atomic????Щ??????????????????????д????????汾??
????1 atomic<Widget*> Widget::pInstance{ nullptr };
????2 Widget* Widget::Instance() {
????3     Widget* p = pInstance;
????4     if (p == nullptr) {
????5         lock_guard<mutex> lock{ mutW };
????6         if ((p = pInstance) == nullptr) {
????7             pInstance = p = new Widget();
????8         }
????9     }
????10     return p;
????11 }
?????????C++????????????????????????????????????????????????????????
????1 static unique_ptr<widget> widget::instance;
????2 static std::once_flag widget::create;
????3 widget& widget::get_instance() {
????4     std::call_once(create?? [=]{ instance = make_unique<widget>(); });
????5     return instance;
????6 }
??????????????????????????????????????????????????????????????????????????C++memory model?ж?static local variable???????The initialization of such a variable is defined to occur the first time control passes through its declaration; for multiple threads calling the function?? this means there’s the potential for a race condition to define first.?????????????????????Ч???????????C++11????
????1 widget& widget::get_instance() {
????2     static widget instance;
????3     return instance;
????4 }
??????Herb Sutter?????????????????“Best of All”???