ruipacheco
ruipacheco

Reputation: 16402

Destructor not being called as expected

I'm writing a server application. Following RIIA, in the constructor of one of my classes I create a file and in the destructor I delete it. This class is wrapped in a unique_ptr. This being a server application, I can only kill it by sending it a signal (SIGINT).

The strange part is that I've placed std::cerr statements on the destructors of the class held by the unique_ptr and they're not called when the application closes/dies.

Is this expected when ctrl+c is pressed or am I missing something obvious in relation to destructors?

Upvotes: 0

Views: 159

Answers (1)

Peter - Reinstate Monica
Peter - Reinstate Monica

Reputation: 16017

Signal processing and C++ exceptions are distinct features. Signals (chiefly a *nix feature) are caught by signal handlers; I believe that although in a sense certainly the "scope" changes, it is changed from outside the C++ run time and thus does not trigger the usual stack unwinding (it's like moving in a second dimension with respect to the stack, so to speak). Googling pointed me to this post which I found interesting: https://gcc.gnu.org/ml/gcc-help/2011-08/msg00253.html.

Upvotes: 1

Related Questions