View previous topic :: View next topic |
Author |
Message |
Ant
Joined: 06 Mar 2004 Posts: 306 Location: Canada
|
Posted: Tue May 23, 2006 11:08 pm Post subject: Threads with Duit |
|
|
Seems threads are now working with Duit (I'll commit to svn in a few minutes).
(Probably they always worked but the FAQ from GTK confused many people).
to make it work (example from leds):
Code: |
int main(char[][] args)
{
Duit.init(args);
//if ( !Thread.supported () ) --- this is a macro: not available in Duit (yet?)
{
Thread.init(null);
gdkThreadsInit();
}
Leds leds = Leds.leds(args);
if ( !leds.closing )
{
Duit.main();
}
return leds.exitCode;
}
|
then any code that runs on a separate thread and updates the GUI (or uses glib functions - not sure) needs to start with gdkThreadsEnter() and end with gdkThreadsLeave():
Code: |
/**
* links the target.
* This is called from the Compile spawned command.
* Params:
* spawn =
* Returns: true
*/
bool linkTarget(Spawn spawn)
{
gdkThreadsEnter();
if ( spawn.exitStatus == 0 )
{
...
execConsole.exec(target.getBaseDirObj(), linkCom, true);
}
compileEnd();
gdkThreadsLeave();
return true;
}
|
Ant |
|
Back to top |
|
|
Ant
Joined: 06 Mar 2004 Posts: 306 Location: Canada
|
Posted: Tue May 23, 2006 11:32 pm Post subject: Re: Threads with Duit |
|
|
Ant wrote: |
then any code that runs on a separate thread and updates the GUI (or uses glib functions - not sure) needs to start with gdkThreadsEnter() and end with gdkThreadsLeave(): |
according to the FAQ we should probably include also a call to Gdk.flush() before gdkThreadLeave().
http://www.gtk.org/faq/#AEN492
( probably the wraping of the gtk_thread_* functions will change to ThreadG.*() )
Ant |
|
Back to top |
|
|
|