emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Timer scheduling and cancel-timer


From: Paul Eggert
Subject: Re: Timer scheduling and cancel-timer
Date: Sun, 20 Jan 2013 11:22:03 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2

On 01/20/2013 07:58 AM, Tomohiro Matsuyama wrote:
>     (setq my-timer
>           (run-with-timer
>            nil 0.1
>            (lambda ()
>              (when my-timer
>                (cancel-timer my-timer)
>                (setq my-timer nil)
>                (sit-for 0.3)))))
> 
> After evaluating this code several times, you may see "zombie" timers
> in timer-list, though the code intends to keep at most one timer.

Hmm, isn't that due to a race in the above code?
A timer can fire when a timer action is running.

Do you get zombie timers with the following?
It should avoid the race.

    (setq my-timer
          (run-with-timer
           nil 0.1
           (lambda ()
             (let ((m my-timer))
               (when m
                 (cancel-timer m)
                 (setq my-timer nil)
                 (sit-for 0.3))))))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]