lundi 7 décembre 2015

Signal handling per process on Windows

In my C++ app I need to catch signal SIGSEGV, so on Linux it's easy, but on Windows I have a problem: signal from another thread didn't catch by handler.

#include <signal.h>
#include <iostream>
#include <thread>

void setPosixSignalHandler() {
    signal(SIGSEGV, [&](int sig) {
        std::cout << "Received SIGSEGV" << std::endl;
        exit(EXIT_FAILURE);
    });
}

void f() {
    raise(SIGSEGV);
}

int main() {
    setPosixSignalHandler();

    std::thread t(f);
    t.join();

    return 0;
}

If I remove multithreading than it's working like a charm. Is it possible to set a single handler for all threads?

I'm using MinGW64.

Aucun commentaire:

Enregistrer un commentaire