Sign in to follow this  
jsepia

[GLFW] Kill a thread whenever the parent dies

Recommended Posts

Hi, I'm working on a game with two threads using GLFW. Input and rendering are running on the main thread, game logic runs on the second thread. When the game ends abnormally (if I pkill it, for example), one of the threads keeps running in the background and eating cpu. This is very annoying when I want to debug the game and kill it whenever I want. Is there a way to make a thread die whenever the parent thread dies too? I tried modifying the destructor but it didn't work:
GameThread::~GameThread()
{
    delete match;
    delete field;
    delete players;

    if(running)
        Kill();
}

This is my Kill() method, by the way. It works fine when I end the game normally:
void GameThread::Kill()
{
    running = false; // this ends the game loop
    glfwWaitThread(thread, GLFW_WAIT);
}

Share this post


Link to post
Share on other sites
When you say "pkill" I assume you're running on Linux. By default, the "kill" derivatives send the SIGTERM signal to the process, and I'm guessing that GLFW doesn't handle that signal "properly".

What you can do is, you can trap the SIGTERM signal yourself (here is an example) and manually shut down your additional threads.

(By the way, I say that GLFW doesn't handle it "properly" because I believe that the framework should handle that sort of thing automatically for you, but anyway...)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this