vedm <email@example.com> wrote:
| nabla <firstname.lastname@example.org> writes:
| > vedm wrote:
| > > Is there a timer function in cmucl? I want to call a function
| > > periodically and in a separate thread. Looking at the "mp"
| > > package I do not see something like "make-timer"..
| > My simple solution:
| > (defun make-timer (fun period)
| > (mp:make-process #'(lambda ()
| > (loop
| > (funcall fun)
| > (sleep period))) :name "timer"))
| Thanks, I guess this will do for my purposes, or at least I will try.
Note that the SLEEP here is implemented internally within CMUCL
with a synchonous "select()" call whose timer arg is the minimum
of all current SLEEPers, and *not* using a SIGALRM interrupt handler,
so it should be safe from the concerns that others have been noting
about interrupt handlers.
 Actually, the minimum of all sleeps and the value represented by
the pair of globals CL::*MAX-EVENT-TO-SEC* & CL::*MAX-EVENT-TO-USEC*,
whichever is smaller. The default values are 1 & 0 respectively
[one second], which can make scheduling sluggish in some cases,
in which case you might want to try this:
(setf cl::*max-event-to-usec* 10000 ; frequent testing during sleeps
Alternatively, if you call MP::STARTUP-IDLE-AND-TOP-LEVEL-LOOPS
during your program's startup [which can be a bit tricky to do
if you use a detached script to start it -- the call must be
the *very* last thing in the startup script], you can leave the
MAX-EVENT-xxx vars alone and things seem to work just fine.
Rob Warnock <email@example.com>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607