Re: Working with signals

Mikael Hallendal <[email protected]> 06 Dec 2002 13:12:14 +0100
Newsgroups gmane.comp.gnome.apps.mr-project.devel
Organization CodeFactory AB
Message-ID <[email protected]>
tor 2002-12-05 klockan 01.08 skrev Roberto Perez:
> Hi!

Hi!

> We are working in mozilla plugin but we have some problems in order to
> separate the two tasks of the plugin a)get the bugs and b) insert them
> into mrp.
> We need to do these taks in separate threads to keep mrp running, since
> the task of getting bugs could take a long time. However the task of
> inserting the bugs into mrp must be done in the main thread ( if not, 
> mrp crashes )
> The problem is if we do a g_thread_join() in the main bug, the main bug
> blocks until the thread has finished, then we think use signals to
> synchronize the two task.
> The idea is: the main thread create the "get_bug_thread" and then
> register the "get_complete" signal to the function that insert it into
> mrp, something like this:

Yep, as you say you need to add the bugs to MrProject from the main
thread.

Though if you do it from a signal callback it will still be done in the
get_bug_thread (since it's that thread that actually runs your
callback).

Since you are only interested in checking if the other thread is
finished you could do it like this:

Have a gboolean "finished" which you check from your mainloop.

g_timeout_add (interval, (GSourceFunc) check_finished, data);

in check_finished you check to see if "finished" is set to TRUE, then
you can know that you can safely read the list and insert them into the
project.

You probably don't have to care about locking here since you only have
one thread that will set the variable and then exit.

(Signals between threads would be a very nice addition :)
 
Regards,
  Mikael Hallendal
-- 
Mikael Hallendal                [email protected]
CodeFactory AB                  http://www.codefactory.se/
                                Cell: +46 (0)709 718 918