getf: Correct docstring.
[sbcl.git] / doc / manual / timers.texinfo
1 @node Timers
2 @comment  node-name,  next,  previous,  up
3 @chapter Timers
4
5 SBCL supports a system-wide event scheduler implemented on top of
6 @code{setitimer} that also works with threads but does not require a
7 separate scheduler thread.
8
9 The following example schedules a timer that writes ``Hello, word'' after
10 two seconds.
11
12 @lisp
13 (schedule-timer (make-timer (lambda ()
14                               (write-line "Hello, world")
15                               (force-output)))
16                 2)
17 @end lisp
18
19 It should be noted that writing timer functions requires special care,
20 as the dynamic environment in which they run is unpredictable: dynamic
21 variable bindings, locks held, etc, all depend on whatever code was
22 running when the timer fired. The following example should serve as
23 a cautionary tale:
24
25 @lisp
26 (defvar *foo* nil)
27
28 (defun show-foo ()
29   (format t "~&foo=~S~%" *foo*)
30   (force-output t))
31
32 (defun demo ()
33   (schedule-timer (make-timer #'show-foo) 0.5)
34   (schedule-timer (make-timer #'show-foo) 1.5)
35   (let ((*foo* t))
36     (sleep 1.0))
37   (let ((*foo* :surprise!))
38     (sleep 2.0)))
39 @end lisp
40
41 @section Timer Dictionary
42
43 @include struct-sb-ext-timer.texinfo
44 @include fun-sb-ext-make-timer.texinfo
45 @include fun-sb-ext-timer-name.texinfo
46 @include fun-sb-ext-timer-scheduled-p.texinfo
47 @include fun-sb-ext-schedule-timer.texinfo
48 @include fun-sb-ext-unschedule-timer.texinfo
49 @include fun-sb-ext-list-all-timers.texinfo