From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.devel Subject: Re: Timer scheduling and cancel-timer Date: Sun, 31 Mar 2013 18:44:14 +0200 Message-ID: <87bo9zh63l.fsf@web.de> References: <20130121005802.c7383f4994ead287e738f96f@cx4a.org> <50FC43DB.6070505@cs.ucla.edu> <20130331201746.cbb41f66c98d4c2be5ad4287@cx4a.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1364748288 4013 80.91.229.3 (31 Mar 2013 16:44:48 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 31 Mar 2013 16:44:48 +0000 (UTC) Cc: Paul Eggert , emacs-devel@gnu.org To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Mar 31 18:45:11 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UMLNT-0003TZ-Bn for ged-emacs-devel@m.gmane.org; Sun, 31 Mar 2013 18:45:07 +0200 Original-Received: from localhost ([::1]:59501 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMLN4-0005vt-Qq for ged-emacs-devel@m.gmane.org; Sun, 31 Mar 2013 12:44:42 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:40324) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMLMz-0005vo-QU for emacs-devel@gnu.org; Sun, 31 Mar 2013 12:44:40 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UMLMy-0005iR-6p for emacs-devel@gnu.org; Sun, 31 Mar 2013 12:44:37 -0400 Original-Received: from mout.web.de ([212.227.15.4]:54583) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMLMx-0005dr-Tc for emacs-devel@gnu.org; Sun, 31 Mar 2013 12:44:36 -0400 Original-Received: from drachen.dragon ([89.204.135.159]) by smtp.web.de (mrweb103) with ESMTPSA (Nemesis) id 0MK20H-1UNiHE1JeH-001EIu; Sun, 31 Mar 2013 18:44:24 +0200 Mail-Followup-To: emacs-devel@gnu.org, Paul Eggert , emacs-devel@gnu.org In-Reply-To: <20130331201746.cbb41f66c98d4c2be5ad4287@cx4a.org> (Tomohiro Matsuyama's message of "Sun, 31 Mar 2013 20:17:46 +0900") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-Provags-ID: V02:K0:zR8y/1HiKrseCOBxZ5+znB+ijKaNBL/MSi5+9kZWNoN D0yA8JOPsZhkUaX8eY9RougZ4Cjjakxi/jBoCmqFWxzdcxPSpi Y9jKf9mhwZh7WiMIr65fsiGDLvXB6RWJv/CAb+llU7rVT7kCfD EM+3UiYruc8z692yUA3LBgXNks7c7rIbYaOPAcUzCk94B3PikR cC5FcB/8AH7feLkRzHPv4lRBLaJT9A3naTDMNfGlzg= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 212.227.15.4 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:158495 Archived-At: Tomohiro Matsuyama writes: > > > (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. I see that, too. To reveal what's happening, I ran the following experiment: --8<---------------cut here---------------start------------->8--- (defvar my-timer nil) (defun start-the-timer () (interactive) (setq my-timer (run-with-timer 0 0.1 (lambda () (cancel-timer my-timer) (sit-for 0.3))))) (advice-add 'timer-event-handler :before (lambda (timer) (when (and (eq timer my-timer) (not (memq my-timer timer-list))) (message "Why is this ever reached?")))) --8<---------------cut here---------------end--------------->8--- If you call `start-the-timer', you get the message "Why is this ever reached?" over and over. Obviously, although the timer object created has been successfully canceled (i.e., removed from `timer-list'), the C code still calls it repeatedly with `timer-event-handler'. Dunno why, but that's not good. Regards, Michael.