Re: Knowing if a GThread is still alive



On Sun, Sep 30, 2012 at 9:36 PM, Vivien Malerba <vmalerba gmail com> wrote:

So I'm looking for some advice on how to check if a GThread (say A) is still alive while my code executes in another thread (say B). I've thought about two ways to do this but could find none which seems to work:
...
 
2) configure thread A to execute a "cleanup" function when it exits (like atexit), but I don't think it's doeable

i think your second option is the better bet.   when each thread exits, use g_idle_add() to call a finalize/clean-up function, each thread calling the same function. 

since it's executed as part of the main loop, single concurrency is guaranteed.   pass an argument indicating which thread is exiting, and then do whatever housekeeping for each that is appropriate. 

as well, you can maintain a variable indicating if any given thread is active: set to true at thread start-up, and then false in the thread finalize callback.

richard


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]