Re: Ho to implement new GSource?



On Thu, 26 Mar 2009 12:17:17 +0100
Tomasz Jankowski <tomcioj gmail com> wrote:


Hello!

I'm working on MT application, which perform some tasks in separated
threads. My application also use GTK+ and it should work on Windows,
so I need to deal somehow with running all functions, which change
GUI from one thread.

I run one thread with GTK's main loop and i want to implement new
source, which will check GAsysnQueue for new elements (passed to it
by other threads) and perform some actions (like updating progress
bars).

I went to GLib documentation and i stuck there. I'm unable to figure
out how main loop works and how can I correctly implement new source
type. I cannot use idle source, because I want to check my async
queue more often. On the other hand I want to understand how main
loop works in GLib. 

You can use g_idle_add(), and any custom GSource object you make is
going to have to do something very similar.  In unix what g_idle_add()
does is put a byte in a pipe on which the main loop has a file
descriptor poll.  In windows I think it uses a windows thread event
object.

Instead of worker threads placing things in a GAsyncQueue, you can pass
them as a data argument when they call g_idle_add().  Or if there is a
special reason to do so you can pass the data onto a queue, and your
idle function can pop it off again.

Chris



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