Q&A's, tips, howto's
kanen
Posts: 145 Joined: Thu Mar 25, 2010 6:24 pm
Contact:
Post
by kanen » Wed Apr 13, 2011 3:14 am
Say you have :
Code: Select all
;
; a define
(define (foo)
(println "Oh Yeah.")
)
;
; and another
(define (foobar)
(dolist (s (sequence 1 10))
(sleep 1000)
)
)
;
; and a timer:
(define (ImaTimer)
(foo)
(timer 'ImaTimer 1)
)
;
; and, some code:
(println "Setting timer...")
(ImaTimer)
(println "Forking...")
(fork (foobar))
;(foobar)
(exit)
The problem is, the timer never fires in the forked process.
But, if you do not fork, changing
(fork (foobar)) to just
(foobar) the timer works fine.
Lutz
Posts: 5289 Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:
Post
by Lutz » Wed Apr 13, 2011 4:32 am
The timer is cancelled from a SIGALRM generated by 'sleep' in the forked child process. If you replace the 'sleep' the timer keeps on going.
Code: Select all
; a define
(define (foo)
(println "Oh Yeah.")
)
;
; and another
(define (foobar)
(dolist (s (sequence 1 10))
(set 'start (time-of-day))
(while (< (time-of-day) (+ start 1000)))
(println "foobar")
)
)
;
; and a timer:
(define (ImaTimer)
(foo)
(timer 'ImaTimer 1)
)
;
; and, some code:
(println "Setting timer...")
(ImaTimer)
(println "Forking...")
(fork (foobar))
Code: Select all
~> newlisp timer
Setting timer...
Oh Yeah.
Forking...
newLISP v.10.3.0 on OSX IPv4/6 UTF-8, execute 'newlisp -h' for more info.
> Oh Yeah.
foobar
Oh Yeah.
foobar
Oh Yeah.
foobar
foobar
Oh Yeah.
foobar
Oh Yeah.
foobar
Oh Yeah.
foobar
Oh Yeah.
kanen
Posts: 145 Joined: Thu Mar 25, 2010 6:24 pm
Contact:
Post
by kanen » Wed Apr 13, 2011 5:49 am
Would anything else cause this?
I have removed every (sleep) from my code and I still have the timer failing when I fork.
Lutz
Posts: 5289 Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:
Post
by Lutz » Wed Apr 13, 2011 2:27 pm
newLISP uses the same fork(), setitimer() and getitimer() functions on all UNIX platforms. Perhaps there are some specifics, how fork() and setitimer() interact on your platform, e.g. some resource contention between the process scheduler and the timer.
kanen
Posts: 145 Joined: Thu Mar 25, 2010 6:24 pm
Contact:
Post
by kanen » Tue Apr 19, 2011 5:15 am
Or... a stray (sleep) call in one of the twenty modules.
Not that I'd ever admit it. :)
Lutz wrote: newLISP uses the same fork(), setitimer() and getitimer() functions on all UNIX platforms. Perhaps there are some specifics, how fork() and setitimer() interact on your platform, e.g. some resource contention between the process scheduler and the timer.