????1???????飺???????
????1??????????????????????????????????????????????????
????2??????New???????????????delete????????
????3??new ??malloc??????????new????????????滹????????????malloc??????????檔
????4????????????????????new int[5]???????????????????λ?á?
????5??????????????? delete [] HeadPtr ?? HeadPtr=nullptr??
????6?????????shared_ptr????????ü??? unique_ptr????С??????????????????????檔
????share_pt<Simple> mySimpleSmartPtr(new Simple());
????auto mySimpleSmartPtr=make_shared<Simple>();
???????????????????????
?????????????<memory>????
????7??????????????????????????????????????????new????malloc() ???????????????????????????????????????share_ptr??unique_ptr.
????8????????share_ptr??????C???????????????unique_ptr????C???????飬???????STL????????????C??????顣
????2???????????????????
????1????????????????????????????????????????????std::lock()??std::try_lock()??????????????????
????2?????????????<atomic>?????????atomic<int> ??Чatomic_int
????????join()??????е???????????
????3?????<atomic>????????????????????????????????о????????????
????4?????<thread>????????????????????????????????????????????????????Operator?????????lambda????????????????????????????threa??????????????????壬????????κ???????
????5?????????????????????????????????????????????????A.sync_with_stdio(true);??????????????????????????
????6??t.join()???????μ???????????????????????????????????????????????????????????UI????
????7?????C++11???1???????????
#include <thread>
#include <iostream>
using namespace std;
int main()
{
cout.sync_with_stdio(true); // Make sure cout is thread-safe
thread t1([](int id?? int numIterations) {
for (int i = 0; i < numIterations; ++i) {
cout << "Counter " << id << " has value ";
cout << i << endl;
}
}?? 1?? 5);
t1.join();
return 0;
}
????8????????????????????????????????
????Request req(100);    thread t{&Request::Process??&req}; t.join();   ????????????????????????????????????????????????????????????????
????9?????????洢?????????thread_local????????????????????????????????????????
????thread_local int n;
????10???????????????????????????????????????C++11 ?????????????????????????<mutex>??????
?????????????????std::mutex  ???????????????????????????壬??????????????????????????????????????????????ε???lock()????try_lock()????????????????
????std::recursive_mutex ??std::mutex ????????????????????ε???lock()??try_lock()????????unlock()??????????????????????????????????
??????????·????? lock()??????????????????????????????????????
????try_lock()???y??????????????????????????????н?????????????????????try_lock()????true????????false??
????unlock():????????е???????????????????????????
????????????壺std::timed_mutex
????std::recursive_timed_mutex
????try_lock_for(rel_tiem): ????????????????????????????漲?????????????????
????try_lock_until(abs_time):??????????????????????????????????????????
????11??????
???????????????????????????????????ú????????????????????????????????????????????????????塣
????std::lock_guard   ??????????ù?????????壬?????????????????
????std::unique_lock ???????????????????????????????????????unique_lock?ж??????????
????std::call_once()???????????漰????????γ?????????????        call_once( mOnceFlag?? &Data::init?? this );
????12?????????????
???????sync_with_stdio(true)???C++???????????????????????????????????????????????????????????????????????????????????????????????????/д????????
????13??????????
??????????????????????????????????????????????????????????????????.<condition_variable>???????????????????
????std::condition_variable ?????unique_lock<mutex>??????????
????std::condition_variable_any ???????κ????????????????????????????notify_one();notify
????_all(); wait(unique_lock<mutex>& lk);
????14??????????????????????????????б???????????C++???????????std::terminate???????????????ó??????std::future?????????????в???????????????????У?????????????????????λ????????????????????????????????????????????
???????std::future??std::promise ????????????????????????к??????????????????á???