Destruction of global static variables and the sequence of thread termination

 

After the main thread main exits, the global variable mutex is not destroyed (destructed) after the child thread is destroyed

Question: After the main thread main exits, the detached sub-thread (C RT managed) and the global static variable (life cycle CRT managed) are destructed.

I flipped through the CRT source code, but did not find their relationship,

But the answer given by the example here is that the end of the detached child thread after the main function returns is after the global static variable is destructed

 

Tucao: Why didn't the designer of this sequential CRT not consider this situation?

Global static variables do not belong to a thread. In order to make mistakes, global static variables should be destructed (destroyed) after all threads are terminated.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324389119&siteId=291194637