My code has the following classes. In other words, there is a static object (singleletone) that creates a stream in CTor, and when its DTor is called, it does some work in the context of this stream (DTor poses some tasks for the stream).
The problem I am facing is that when DTor of B is called, there are no other threads in this process - it seems that this thread is killed by cleaning the process before calling the class B destructor.
Does anyone know why this is happening? and how to avoid it?
UPD: Problems only arise when creating Singleton from a DLL. Everything works fine when Singleton is created from the same executable.
I am using VS2017
Singleton.dll (Ah + A.cpp) Ah -->
==================================================== ================================
An executable file that uses the main.cpp DLL
#include "stdafx.h" #include "Ah" int main() { auto a = A::instance(); return 0; }
Updated using compiled code. Now, if you compile the first two files as a DLL, and then set a breakpoint in the destructor, you will see that the stream with the lambda function does not exist ....
UPDATE: found answer from myslef. On Windows, a static object from a DLL is unloaded to the last point when all threads are already cleaned up https://msdn.microsoft.com/en-us/library/windows/desktop/dn633971(v=vs.85).aspx
c ++ multithreading destructor std singleton
Boris Bolshem
source share