all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: "Stephen J. Turnbull" <stephen@xemacs.org>
Cc: tromey@redhat.com, emacs-devel@gnu.org
Subject: Re: threads and kill-buffer
Date: Thu, 06 Sep 2012 13:58:34 +0300	[thread overview]
Message-ID: <83harbct9h.fsf@gnu.org> (raw)
In-Reply-To: <87ipbrsdza.fsf@uwakimon.sk.tsukuba.ac.jp>

> From: "Stephen J. Turnbull" <stephen@xemacs.org>
> Cc: tromey@redhat.com,
>     emacs-devel@gnu.org
> Date: Thu, 06 Sep 2012 18:22:01 +0900
> 
> Eli Zaretskii writes:
>  > > From: "Stephen J. Turnbull" <stephen@xemacs.org>
> 
>  > > If the thread wants to do anything further with this buffer, it must
>  > > do so before switching buffers, because the current (dead) buffer
>  > > will become inaccessible as soon as it does switch buffers.
>  > 
>  > This is another problem, one that exists today: switching buffers
>  > could kill the buffer we are switching away of (e.g., via some hook).
> 
> No, because there's nothing we can do about such a hook unless we put
> it there, and nobody does.  Under the proposed "POSIX deletion"
> semantics, however, we can know it's coming, as long as we can detect
> that the current buffer is killed.  And we are guaranteed that we can
> read it, we can save it, etc.

Again, I was primarily bothered with preserving the existing
semantics, not to allow new features.

>  > > Even to the extent that it is possible, I don't see why it's a good
>  > > idea.
>  > 
>  > Because it keeps the old code in working condition, and it keeps the
>  > programmer sane.
> 
> Well, no.  Old code won't work (it will deadlock, interleave writes
> that should be sequenced, etc) without being rewritten for threaded
> environments, unless it's only ever used single-threaded anyway.

I meant to say that the old code that runs in a single thread will
still work, in the presence of other threads that do unrelated things,
like fetch news group articles.  If the old code is rewritten to take
advantage of threads, it will have to be adapted to this issue as part
of the rewrite.

> Unless you're talking about some random other thread killing your
> buffers

Yes.

> in which case killing a buffer is only one of the more drastic of
> nasty things that other thread could do.

That's the "nasty thing" Tom raised in this discussion, so that's what
I'm talking about.  Other nasty things warrant separate discussions.

> Having a buffer killed out from under my code is hardly the first
> thing I'd worry about if I were writing a threaded program.

And you'd be wrong: lots of low-level internals in Emacs assume
without checking that the current buffer exists and is valid.  E.g.,
redisplay will crash and burn if that somehow became false in the
middle of its work.

> I'm describing the semantics of a buffer X killed by thread A as seen
> from thread B where it is current, and according to your proposal to
> thread B thqe buffer will appear to be live indefinitely.  If thread B
> is the reader, it will never detect that the buffer is dead, and will
> keep on trying to read from it forever when it could be doing useful
> work.
> 
> Yes, you could use an alternative synchronization method where thread
> A explicitly sends thread B a message "hey, I killed your buffer", but
> why make the user do it when "buffer is dying, so let's read what's
> left and then get on with our life" will automatically DTRT?

If that's what is desired, then thread B could switch away from that
buffer, after killing it, and Bob's our uncle.

IOW, you can write your code so that a killed buffer disappears
shortly, if that's what you need.

>  > If you mean that the same buffer is current in both the reader and the
>  > writer, then that's a situation that cannot exist in the current code,
> 
> What do you mean by "current code"?

The code on the trunk.

> (defvar read-mark (make-marker))
> 
> (defun writer ()
>   (set-marker read-mark (point))
>   (insert "Hi, Eli!\n")
>   (reader))
> 
> (defun reader ()
>   (mail-to-eli (buffer-substring read-mark (point)))
>   (writer))
> 
> (writer)
> 
> No set-buffers needed.  Everything in the current buffer.

Invalid programs are not interesting for discussing design decisions.

> You could also remove the recursive calls and just loop:
> 
> (while t (writer) (reader))

And why is this a problem in the context of this discussion?  No
buffer is killed anywhere in sight, AFAICS.



  reply	other threads:[~2012-09-06 10:58 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-04 20:36 threads and kill-buffer Tom Tromey
2012-09-04 20:43 ` Lars Ingebrigtsen
2012-09-04 21:03 ` Paul Eggert
2012-09-05  2:53 ` Eli Zaretskii
2012-09-05 14:20   ` Sam Steingold
2012-09-05 16:35     ` Eli Zaretskii
2012-09-05 16:50       ` Sam Steingold
2012-09-05 16:54         ` Eli Zaretskii
2012-09-05 19:19         ` Stephen J. Turnbull
2012-09-05 20:34           ` Tom Tromey
2012-09-06  0:20             ` Stephen J. Turnbull
2012-09-06  1:53               ` Tom Tromey
2012-09-06  8:34                 ` Stephen J. Turnbull
2012-09-05 18:13     ` Stefan Monnier
2012-09-05 18:28     ` Tom Tromey
2012-09-05 19:14       ` Stefan Monnier
2012-09-05 18:20   ` Tom Tromey
2012-09-05 19:00     ` Stephen J. Turnbull
2012-09-05 19:10       ` Tom Tromey
2012-09-05 19:50         ` Eli Zaretskii
2012-09-05 20:48           ` Stephen J. Turnbull
2012-09-06  5:16             ` Eli Zaretskii
2012-09-06  9:22               ` Stephen J. Turnbull
2012-09-06 10:58                 ` Eli Zaretskii [this message]
2012-09-07  1:26                   ` Stephen J. Turnbull
2012-09-05 20:25         ` Stephen J. Turnbull
2012-09-05 19:45       ` Eli Zaretskii
2012-09-05 19:46     ` Eli Zaretskii
2012-09-06  2:28       ` Stefan Monnier
2012-09-06  5:24         ` Eli Zaretskii
2012-09-06 12:32           ` Stefan Monnier
2012-09-05  3:49 ` SAKURAI Masashi
2012-09-05  4:34 ` Dmitry Antipov
2012-09-05  9:44   ` martin rudalics
2012-09-05 16:28     ` Eli Zaretskii
2012-09-06  7:19       ` martin rudalics
2012-09-06  7:56         ` Eli Zaretskii
2012-09-06 14:41           ` martin rudalics
2012-09-06 14:55             ` Eli Zaretskii
2012-09-06 16:04               ` martin rudalics
2012-09-06 17:07                 ` Stefan Monnier
2012-09-06 17:37                   ` martin rudalics
2012-09-06 18:22                     ` Eli Zaretskii
2012-09-06 19:25                       ` Eli Zaretskii
2012-09-07  9:52                       ` martin rudalics
2012-09-06 21:28                     ` Stefan Monnier
2012-09-07  9:52                       ` martin rudalics
2012-09-07 14:44                         ` Stefan Monnier
2012-09-07 16:13                           ` martin rudalics
2012-09-07 18:31                             ` Stefan Monnier
2012-09-06 20:49             ` PJ Weisberg
2012-09-07  5:52               ` Eli Zaretskii
2012-09-07 15:28                 ` PJ Weisberg
2012-09-08 14:58                   ` Nix
2012-09-08 15:21                     ` Eli Zaretskii
2012-09-08 19:45                     ` Stefan Monnier
2012-09-05 13:41 ` Stefan Monnier
2012-09-05 14:34   ` Tom Tromey

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=83harbct9h.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=stephen@xemacs.org \
    --cc=tromey@redhat.com \
    /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.