# [GLFW] Kill a thread whenever the parent dies

This topic is 3112 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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
}


##### 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 on other sites
That's exactly what I needed. Thanks a lot! (: