Subject: Re: timer in cmucl?
From: rpw3@rpw3.org (Rob Warnock)
Date: Fri, 29 Apr 2005 05:02:22 -0500
Newsgroups: comp.lang.lisp
Message-ID: <RYqdnZjKRdyzm-_fRVn-sw@speakeasy.net>
vedm  <ns@nospam.com> wrote:
+---------------
| nabla <nablaone_nospam@nospam.gmail.com> 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[1], and *not* using a SIGALRM interrupt handler,
so it should be safe from the concerns that others have been noting
about interrupt handlers.


-Rob

[1] 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
	      cl::*max-event-to-sec* 0)

    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			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607