Re: Multiple threads and gtk_main()



Gabriele Greco escreveu:
I've a few threads (more than one) doing some work (not accessing GTK functions), I'd like to have a general way to make them notify their work to the main loop.

I used the g_idle_add() in the previous context where I had only a thread with this behaviour, but with two or more threads the g_idle_add() method of notification is not correct IMHO (what happens if two threads call g_idle_add() before the call of the first one is processed by the glib main loop?)
[...]
I though about using a GAsyncQueue for every thread but in this way the problem I have is how to notify the main loop that there is something on a queue, I've not found anything in the documentation... I fear the only way it's to use a pipe or a socket, or an idle function, but in this case I will occur again in the locking problem, I hope I'm wrong about this so I'm asking here :)
Make your threads add stuff to a single GAsyncQueue. Let an idle function (or a timeout function) always run, that checks the GAsyncQueue and does something if there is something to do, or simply returns if it is empty. Wouldn't that work?



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