-
static thread_local 인스턴스의 소멸 시점프로그래밍/c++ 2019. 3. 5. 18:45반응형#include <chrono>#include <thread>#include <iostream>using namespace std;class Foo{public:Foo() {cout << "call constructor" << endl;}~Foo() {cout << "call destructor" << endl;}};int main(){thread thrd{[]{static thread_local Foo foo;this_thread::sleep_for(5s);}};cout << "before join" << endl;thrd.join();cout << "after join" << endl;return 0;}
스레드가 종료될 때 제거된다. 당연하게도.
반응형'프로그래밍 > c++' 카테고리의 다른 글
c++ namespace 로 감싸진 클래스, 구조체 전방 선언 (0) 2020.08.26 std::clamp (0) 2019.11.24 ::operator new, ::operator delete (0) 2018.10.03 c++ 클래스 상속 관계에서의 메모리 정렬 (0) 2018.09.16 비쥬얼 스튜디오 c++, 포인터에서 배열 보기 (0) 2018.09.09