SFML community forums
Help => System => Topic started by: kreed on September 08, 2012, 06:04:24 pm
-
So, I need to find out when a thread is done. Is this possible? I need to use it so that when a specific thread is closed, my other thread terminates. Also, is there a way to find out if a thread is currently running? Essentially, I have two threads. When any of my threads stop running, I want to terminate all my other threads.
-
SFML doesn't provide functionalities to check this, but it can be more or less easily get implemented.
For example you have a boolean variable in a shared scope and when the thread starts you lock it, then set it to true, unlock it, do your thing and at the end lock, unset and unlock it.
Mean while you'll be able to check if the boolean is set or not and thus get the current 'state' (you'll also need to lock it from the other threads, against what many developers might say, booleans are not guaranteed to be atomic). ;)
There are also other ways and maybe with the right design you won't even need them... ;)
-
Yeah, I thought about doing something like that. This is really just a placeholder so I can get something working quickly. Later I'll terminate from inside the thread using my event system. I just wanted a quick fix to move forward :P.
-
Later I'll terminate from inside the thread using my event system.
Although I guess you didn't mean it that way, I still wanted to point out that calling terminate() on a thread isn't a good solution, it's better just to let the thread naturally finish (i.e. it gets to the end of the threaded function). ;)