RE: program sleep question



One idea...
Would something like this work...

void gtk_sleep(long seconds){
  time_t end_time=time(NULL)+seconds;
  while(time(NULL)<end_time){
    if(gtk_events_pending())
      gtk_main_iteration();       /* Refresh if needed */
    /* some kind of yield here so that it isn't a busy loop...*/
  }
}

> -----Original Message-----
> From: Roberto Zunino [mailto:zunino@CLI.DI.Unipi.IT]
> Sent: Friday, June 25, 1999 3:26 PM
> To: Fox, Kevin M
> Subject: RE: program sleep question
> 
> 
> 
> On Fri, 25 Jun 1999, Fox, Kevin M wrote:
> 
> > Already looked at that. It would require me to break up my 
> function into
> > like 20 small functions that call each other one by one by 
> the use of
> > gtk_timeout_add...
> > Not a nice solution. :(
> > I was hoping for a way around that kind of ugly design.
> > 
> > Thanks anyway...
> > 
> 
> You could consider splitting your app in two processes and communicate
> through gdk_input_add and pipes. The problem is: you want 
> your window to
> refresh _and_ your program to sleep() or do calculations. 
> Sigh, I think almost every app which makes network connections or does
> long calculations or <add a blocking activity here> must 
> split into more
> processes if it wants to keep the gui working. I had to do this to
> implement a simple (networked) tic-tac-toe...
> 
> We haven't thread-safe glib/gtk yet... but I thank the gtk 
> developers for
> gdk_input_add: without it, multiprocessing would be 
> impossible (without
> tricks).
> 
> Regards,
> Zun.
> 



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