[Gambas-devel] 1.9.20 Timer Bug

Daniel Campos danielcampos at ...45...
Wed Sep 7 09:04:53 CEST 2005


I Benoit:

I've found some strange things with the new native timer implementation:

1) I'm not sure if this first one is a bug, but if you write just a
console program like this:


PRIVATE hTimer AS Timer

PUBLIC SUB hTimer_Timer()

  PRINT "HELLO"

END

PUBLIC SUB Main()

   hTimer=NEW Timer AS "hTimer"
   hTimer.Delay=100
   hTimer.Enabled=TRUE

END

The program just exits from the Main() function and stops. I think It
should be alive, like if a descriptor were beeing watched, in order to
allow console programs with timers to not finish in a loop while they're
alive...

=======================================================================================

2) I think this second one is a bug, but I'm not sure if it depends on
gb.net or the gbx2 interpreter. This little program works, with gb.net,
as expected (it never finishes):

PRIVATE hProc AS ServerSocket

PUBLIC SUB Main()

  hProc = NEW ServerSocket
  hProc.Port = 30000
  hProc.Listen()

END

...But, if I add a Timer, it stops inmediatly!

PRIVATE hProc AS ServerSocket
PRIVATE hTimer AS Timer

PUBLIC SUB hTimer_Timer()

  PRINT "TIME"

END

PUBLIC SUB Main()

  hTimer = NEW Timer AS "hTimer"
  hTimer.Delay = 100
  hTimer.Enabled = TRUE

  hProc = NEW ServerSocket
  hProc.Port = 30000
  hProc.Listen()

END

Should I implement some special in the gb.net component? I suppose I
have not to reimplement the timer hook, as I have not main loop in
that component... However, If I use a Process with the "FOR READ" flag
instead of a ServerSocket, the code seems to work normally while there's
data to be read from the descriptor.


======================================================================================

3) More strange things :-) If I try to write a loop at the end of the
main function so the program does not finish, the processor takes 100%
use:

PRIVATE hProc AS ServerSocket
PRIVATE hTimer AS Timer

PUBLIC SUB hTimer_Timer()

  PRINT "TIME"

END

PUBLIC SUB Main()

  hTimer = NEW Timer AS "hTimer"
  hTimer.Delay = 100
  hTimer.Enabled = TRUE

  hProc = NEW ServerSocket
  hProc.Port = 30000
  hProc.Listen()

  DO WHILE TRUE
    WAIT 0.01
  LOOP

END

...It can be fixed if I use WAIT 0.1 instead of 0.01, but in that case
the program is idle a lot of time sleeping... I'm not sure if this is
a bug or the normal effect of looping in short intervals.

===========================================================================

Anyway, there are two main problems there:

1) A program with a timer should wait until the Timer is disabled.
2) A program with a descriptor beeing watched (ServerSocket) works, but
if I add a timer it just finishes...  


  I made a temporally hack in the gbx_process.c file, so it waits when
there's a timer, and the program with the ServerSocket does not need
the loop, but I suppose there's more work to do it in the right way:

static bool do_loop(bool canBlock, struct timeval *wait)
{
        
        ....
	
        if (EVENT_check_post())
		return FALSE;
		
	/* Hack */	
	if (_timers)
	{
		if (ARRAY_count(_timers)) 
		{
			ret=TRUE;
		}
	}
        /* End of hack :-) */

	return ret == 0;
}



Regards,

D. Campos






More information about the Devel mailing list