Re: sleep(1) and a-sync timer...

From: Fons Rademakers (Fons.Rademakers@cern.ch)
Date: Mon Aug 03 1998 - 13:42:17 MEST


Hi Stas,

   the problem is that sleep() and a-synchronous timers both use SIGALRM
and they interfere. With the lastest ROOT (2.00/10) you can do it without
MyTimer all in Loop() like this:

void MyWin::Loop() {
  while(gFlag) {
    fprintf(stderr,"loop");
    sleep(1);
    gSystem->ProcessEvents();
  }
}

Cheers, Fons.




Stanislav Terechtchenko wrote:
> 
>         Hi Rooters.
>  I have the simple GUI code. If the call sleep(1) in method
> MyWin::Loop() is commented everything works well, otherwise
> there is no more reaction on the button click. Any hints?
>         Thank you.
>                 Stas.
> 
> ------------------------------------------------------------
> #include <stdlib.h>
> #include "TROOT.h"
> #include "TApplication.h"
> #include "TGClient.h"
> #include "TGFrame.h"
> #include "TGButton.h"
> #include "TTimer.h"
> #include "TSystem.h"
> 
> Int_t gFlag = 0;
> 
> class MyTimer : public TTimer {
> public:
>   MyTimer(Long_t ms = 1000, Bool_t mode = kFALSE) : TTimer(ms, mode) {}
>   Bool_t Notify() {
>     fprintf(stderr,"Notify\t");
>     gClient->HandleInput();
>     Reset();
>     fprintf(stderr,"OK\n");
>     return kFALSE;
>   }
> };
> 
> class MyWin : public TGMainFrame {
>   TGTextButton *fButton;
>   MyTimer *fTimer;
> public:
>   MyWin(const TGWindow *p, UInt_t w, UInt_t h);
>   virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t);
>   void Loop();
> };
> 
> MyWin::MyWin(const TGWindow *p, UInt_t w, UInt_t h) : TGMainFrame(p, w, h)
> {
>   fButton = new TGTextButton(this,"Click here",150);
>   fButton->Associate(this);
>   MapSubwindows();
>   MapWindow();
>   fTimer = new MyTimer();
>   gSystem->AddTimer(fTimer);
> }
> 
> Bool_t MyWin::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
> {
>    switch (GET_MSG(msg)) {
>       case kC_COMMAND:
>          switch (GET_SUBMSG(msg)) {
>             case kCM_BUTTON:
>             case kCM_MENU:
>                switch (parm1) {
>                   case 150:
>                     if(gFlag) gFlag = 0;
>                     else {
>                       gFlag = 1;
>                       Loop();
>                     }
>                   default:
>                      break;
>                }
>             default:
>                break;
>          }
>       default:
>          break;
>    }
>    return kTRUE;
> }
> 
> void MyWin::Loop() {
>   while(gFlag) {
>     fprintf(stderr,"loop");
>     //    sleep(1);
>   }
> }
> 
> extern void InitGui();
> VoidFuncPtr_t initfuncs[] = { InitGui, 0 };
> 
> TROOT root("GGG", "GGG test environement", initfuncs);
> 
> main(int argc, char **argv)
> {
>   TApplication theApp("App", &argc, argv);
>   new MyWin(gClient->GetRoot(), 400, 220);
>   //  TBrowser *br = new TBrowser("browser","H2 Root online browser");
>    theApp.Run();
>    return 0;
> }

-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland          Phone: +41 22 7679248
E-Mail: Fons.Rademakers@cern.ch              Fax:   +41 22 7677910



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:35 MET