FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Threads with Duit

 
Post new topic   Reply to topic     Forum Index -> gtkD
View previous topic :: View next topic  
Author Message
Ant



Joined: 06 Mar 2004
Posts: 306
Location: Canada

PostPosted: Tue May 23, 2006 11:08 pm    Post subject: Threads with Duit Reply with quote

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
View user's profile Send private message
Ant



Joined: 06 Mar 2004
Posts: 306
Location: Canada

PostPosted: Tue May 23, 2006 11:32 pm    Post subject: Re: Threads with Duit Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> gtkD All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group