Home > Back-end >  The static thread_local members release problem
The static thread_local members release problem

Time:11-07


 class C{
Public:
(C) {}
~ (C)
{
STD: : cout & lt; <"Delete" c & lt; }
};

The class CallData
{
Public:
Struct B
{
~ (B)
{
STD: : cout & lt; The delete CallData: : q;
}
};

The static thread_local C * q;
The static thread_local B B;
};

Thread_local C * CallData: : q=new C;
CallData thread_local CallData: : B: : B;

Void fun1 ()
{
STD: : cout & lt; CallData: : b;
}

Int main ()
{
STD: : thread t1 (fun1);
T1. The join ();

STD: : cin. The get ();
return 0;
}



static members destructor sequence is defined object after first destructor,
If is the definition of object b let it after I use destructors release q memory should be safe?




The second q
CallData thread_local CallData: : B: : B;
Thread_local C * CallData: : q=new C;
I also try to change the order they are defined, found that memory, also can release q
But it should be unsafe right? Q of the pointer value is not directly destroyed, so you can delete drop, some compilers may direct the value of the pointer
  • Related