Discussion:
Working with signals
Roberto Perez
2002-12-05 00:04:40 UTC
Permalink
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:


static
void main_thread(...)
{
[....]
g_thread_create(get_bug_thread,....);
g_signal_connect(....,"get_complete", insert_bugs, .... );
[....]
}

static
void get_bug_thread(...)
{
// Get the bugs
g_signal_emit(....,"get_complete",....);
}

static
void insert_bugs(...)
{
//Insert it into mrp
}

With this coding the main thread doesnt stop and the bugs are only
inserted when all of them are collected.

This is the theory, the problem is we dont know how to use signals.
Reading the gtk tutorial and the gtk api, we notice that the functions
that manage signals are widely linked to objects but we dont work with
objets in the plugin.

How can we use signals in this context ???


Regards.

-> Roberto <-
--
oooO
/ __\
| \ _ GNOME Desktop //||\\ www.gnome.org
\___/
Roberto Perez
2002-12-05 00:08:56 UTC
Permalink
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:


static
void main_thread(...)
{
[....]
g_thread_create(get_bug_thread,....);
g_signal_connect(....,"get_complete", insert_bugs, .... );
[....]
}

static
void get_bug_thread(...)
{
// Get the bugs
g_signal_emit(....,"get_complete",....);
}

static
void insert_bugs(...)
{
//Insert it into mrp
}

With this coding the main thread doesnt stop and the bugs are only
inserted when all of them are collected.

This is the theory, the problem is we dont know how to use signals.
Reading the gtk tutorial and the gtk api, we notice that the functions
that manage signals are widely linked to objects but we dont work with
objets in the plugin.

How can we use signals in this context ???


Regards.

-> Roberto <-
--
oooO
/ __\
| \ _ GNOME Desktop //||\\ www.gnome.org
\___/
Mikael Hallendal
2002-12-06 12:12:14 UTC
Permalink
Post by Roberto Perez
Hi!
Hi!
Post by Roberto Perez
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
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 ***@codefactory.se
CodeFactory AB http://www.codefactory.se/
Cell: +46 (0)709 718 918
Loading...