Page 1 of 1

ticker reset crashes

Posted: Tue Sep 05, 2006 8:55 pm
by HPW
Testing the ticker code from the doc work so far, but trying to reset it as desribed crashes newLISP:

Code: Select all

> (define (ticker)(println (date)) (timer 'ticker 10.0))
(lambda () (println (date)) (timer 'ticker 10))
> (ticker)
Tue Sep 05 22:52:04 2006
10
> Tue Sep 05 22:52:14 2006

> Tue Sep 05 22:52:24 2006

> (define (ticker)(println (date)) (timer 'ticker 0.0))
(lambda () (println (date)) (timer 'ticker 0))
> (ticker)
Tue Sep 05 22:52:31 2006
0
> Tue Sep 05 22:52:31 2006
Tue Sep 05 22:52:31 2006
Tue Sep 05 22:52:31 2006
Tue Sep 05 22:52:31 2006
Tue Sep 05 22:52:31 2006
Tue Sep 05 22:52:31 2006
Tue Sep 05 22:52:31 2006
Tue Sep 05 22:52:31 2006
Tue Sep 05 22:52:31 2006
I tested with newLISP-tk and the DLL version.

Posted: Tue Sep 05, 2006 9:45 pm
by Lutz
You cannot change a function while it is running. That will always crash.

To stop the ticker you could set some global variable for the ticker time and then change that variable to a different value, or some similar scheme.

Lutz

Posted: Wed Sep 06, 2006 5:39 am
by HPW
I tried the follwoing but I still gets the crash:

Code: Select all

newLISP v.8.9.8 on Win32 MinGW.

> (setq MyTime 10.0)
10
> (define (ticker)(println (date)) (timer 'ticker MyTime))
(lambda () (println (date)) (timer 'ticker MyTime))
> (ticker)
Wed Sep 06 07:37:04 2006
10
> Wed Sep 06 07:37:14 2006

> Wed Sep 06 07:37:24 2006

> (setq MyTime 0.0)
0
> Wed Sep 06 07:37:34 2006
Wed Sep 06 07:37:34 2006
Wed Sep 06 07:37:34 2006
Wed Sep 06 07:37:34 2006
Wed Sep 06 07:37:34 2006
Wed Sep 06 07:37:34 2006
....
....
What is wrong?
Seems to get into a endless loop and gets some overflow?

Posted: Wed Sep 06, 2006 3:06 pm
by HPW
>Seems to get into a endless loop and gets some overflow?

Lutz, any idea here?

Posted: Wed Sep 06, 2006 3:55 pm
by Lutz
Yes, after reviewing the code I realize setting the time to 0.0 only works on UNIX. On Win32 the timer is implemented in a different way using windows thraeds and watching the time in the thread, it is taking the 0.0 as a very short time and goes into a loop.

But I am sure there is a way to implement that feature in Win32 too. Look out for it in the next development version.

Meanwhile you could use this workaround:

Code: Select all

(define (ticker)
    (println (date)) 
    (if (> MyTime 0.0) (timer 'ticker MyTime)))
Lutz

Posted: Wed Sep 06, 2006 4:03 pm
by HPW
But I am sure there is a way to implement that feature in Win32 too. Look out for it in the next development version.
Great! And thanks for the workaround.