Re: SwingWorker like interface in glib main loop?

On Tue, 9 Sep 2008 16:38:16 +0200 (MEST)
"DANIELLLANO terra es" <DANIELLLANO terra es> wrote:
> I would like to have a extremely simple API in glib for doing this
> kind of blocking calls as easily as possible.
> Do you guys think a simple API like SwingWorker could be integrated
> in glib?

There already is one, and it is called g_thread_create(). What you need
to do is:

1.  Write the function which opens and reads your NFS file (the
equivalent of writing the doInBackground() method in your example).

2.  Execute it with g_thread_create() (the equivalent of
worker.execute() in your example)

3.  When completed, inform the event loop in the main GUI thread with
g_idle_add() (the equivalent of the done() method in your example).

If you are not familiar with multithreaded programming then avoid shared
variables.  Once you have shared variables you need to concern yourself
with mutexes to ensure memory synchronisation and visibility - as you
would have to do with Java also.  glib has the tools to deal with this
if you need them however (namely mutexes and condition variables).


PS: I am not a glib developer.

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