Re: Knowing if a GThread is still alive

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

 



Good timing as I have this exact same question.

The problem is there is no "thread finalize callback" to use as that would be ideal. It seems the only way that you can know that a thread is done is by using g_thread_join, which causes the current thread to wait. So, for now, what I did was spin up a thread to handle the thread that I care about so I can wait for the other thread to finish using the g_thread_join method. Then I use a signal to tell me when that thread is finished (ie, gets passed the g_thread_join call).

It would be nice to know what the official line on this is...the docs state "There are better ways to find out if your thread is still alive" but does not offer up what that better way is. It seems that a callback would be the most flexible way to handle it.

-Jeff



On Mon, Oct 1, 2012 at 1:21 PM, richard boaz <ivor.boaz@xxxxxxxxx> wrote:
On Sun, Sep 30, 2012 at 9:36 PM, Vivien Malerba <vmalerba@xxxxxxxxx> 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

_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
https://mail.gnome.org/mailman/listinfo/gtk-list


_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
https://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux