all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Miles Bader <miles.bader@necel.com>
Cc: emacs-devel@gnu.org
Subject: Re: Should `cancel-timer' use `delete' instead of `delq'?
Date: Wed, 06 Sep 2006 11:38:16 +0900	[thread overview]
Message-ID: <buoodttwwh3.fsf@dhapc248.dev.necel.com> (raw)
In-Reply-To: <EIENLHALHGIMHGDOLMIMMEBNCLAA.drew.adams@oracle.com> (Drew Adams's message of "Tue, 5 Sep 2006 19:09:11 -0700")

"Drew Adams" <drew.adams@oracle.com> writes:
> I was able to be bitten by it, using C-M-x on the defvar.

That's a good point, but it's also a very special case -- if you're
using a debugging command to _force_ a construct to act in an abnormal
manner, you presumably know what your doing.

> And the general point applies to setq as well.

But I think the answer is not a macro, because there's an obvious, simple, and
extremely widespread idiom for dealing with this situation, which every
programmer should know about (if they don't, they're unlikely to realize they
should be using the special macro):

   (if var (free-non-gced-thing var))
   (setq var (make-non-gced-thing))

Not exactly rocket science...

> To me, it makes sense to have a construct for defining a timer, which
> doesn't also automatically activate it. Why not separate the two acts, as we
> do (by default) with advice? As it stands now, to create a timer that is not
> activated, you must create-and-activate it, and then cancel it.

Er, there _is_ such a function already:  `timer-create'.

But anyway, that doesn't help: the problem is when code "forgets" about
about an activated timer.  If you do (setq my-timer (timer-create)), and
the old value of my-timer was an activated timer, you're going to leak
the old timer even though the new timer is not activated.

>     Is this potential problem really any more widespread than millions of
>     other very similar bugs though?  This is exactly the same as many other
>     sorts of resource allocation/deallocation;
>
> Show us the millions of other very similar bugs, and we can compare ;-).

   static char *buf = 0;

   void init_my_package ()
   {
           buf = malloc (100);
           ...
   }

Whoops!

> I think that one natural, if erroneous, expectation is that the orphan timer
> will naturally go by the wayside at some point, and need not be thought much
> about. There are other, just as natural, expectations that would be more
> correct, but that expectation is a possible and reasonable one: don't worry
> about that zombie timer; it's history; it may be toast already.

Huh?  It doesn't seem reasonable or natural at all.  Activated timers
have an externally visible effect, so clearly they can't simply "go
away."

Someone writing code using timers needs to know this.

-miles

-- 
Come now, if we were really planning to harm you, would we be waiting here,
 beside the path, in the very darkest part of the forest?

  reply	other threads:[~2006-09-06  2:38 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-05  0:14 Should `cancel-timer' use `delete' instead of `delq'? Drew Adams
2006-09-05  1:44 ` Miles Bader
2006-09-05 15:38   ` Stefan Monnier
2006-09-05 16:20     ` Drew Adams
2006-09-05 17:22       ` Stefan Monnier
2006-09-05 17:36         ` Drew Adams
2006-09-05 20:46           ` Kevin Rodgers
2006-09-05 21:24             ` Drew Adams
2006-09-06  1:11               ` Miles Bader
2006-09-06  2:09                 ` Drew Adams
2006-09-06  2:38                   ` Miles Bader [this message]
2006-09-06  6:31                     ` Drew Adams
2006-09-06  6:48                       ` Miles Bader
2006-09-06  7:29                       ` David Kastrup
2006-09-06 14:00                       ` Stefan Monnier
2006-09-06 15:27                         ` Drew Adams
2006-09-06  6:38                   ` David Kastrup
2006-09-05 21:56     ` David Kastrup
2006-09-06  0:59       ` Stefan Monnier
2006-09-06 19:05     ` Richard Stallman
2006-09-05 19:13 ` Stuart D. Herring
2006-09-05 19:22   ` Drew Adams
2006-09-06  8:49 ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=buoodttwwh3.fsf@dhapc248.dev.necel.com \
    --to=miles.bader@necel.com \
    --cc=emacs-devel@gnu.org \
    --cc=miles@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.