unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Philipp Stephani <p.stephani2@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: phst@google.com, emacs-devel@gnu.org
Subject: Re: [PATCH] Support threads in modules
Date: Mon, 12 Jun 2017 15:04:23 +0000	[thread overview]
Message-ID: <CAArVCkSRH4aVzf=oCiFv73pxKQqJ+Yh53NiCnSPUfKMbZ45QSg@mail.gmail.com> (raw)
In-Reply-To: <83mv9e6026.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 3284 bytes --]

Eli Zaretskii <eliz@gnu.org> schrieb am So., 11. Juni 2017 um 17:01 Uhr:

> > From: Philipp Stephani <p.stephani2@gmail.com>
> > Date: Sat, 10 Jun 2017 19:58:40 +0000
> > Cc: emacs-devel@gnu.org, phst@google.com
>
> There's no point in arguing further, as you've already submitted a
> patch that I agree with.  But just for the record, a couple more
> comments to clarify the issue.
>

Thanks. Please note there's no real argument, just a matter of explicitly
making some decisions and documenting them.


>
> > > You were AFAIU talking about accesses to Lisp objects, and these are
> > > only possible via Lisp, which can only be run in a single thread at a
> > > time.  So if the non-Lisp threads of any kind can enter this picture,
> > > in a way that module functions will be run by those threads and access
> > > Lisp objects, please describe such a use case, so we all are on the
> > > same page regarding the situations we are considering.
> >
> > Such a use case is what these assertions should guard against. Calling
> > environment functions from non-Lisp threads is undefined behavior, and
> > these assertions are meant to protect module developers against them.
>
> Right.  But these assertions should IMO not by themselves invoke
> undefined behavior, which dereferencing a NULL pointer does.
>

Yes, as discussed in the other thread these shouldn't be easserts.


>
> > > Once again: there _are_ legitimate situations in Emacs when for a
> > > short time current_thread is NULL.  If you assume that these
> > > situations don't happen, your code will sooner or later crash and
> > > burn.  I'm saying this because I once thought current_thread should be
> > > non-NULL at all times, and my code which assumed that did crash.
> > >
> >
> > I've reviewed the threads code, and I'm quite sure that current_thread
> can
> > never be NULL during check_thread. current_thread is only NULL between
> > exiting a Lisp thread and resuming execution in another thread after
> > reacquiring the GIL. The evaluator doesn't run during that phase, and
> > therefore no module functions can run.
> > current_thread could only be NULL during check_thread if called from a
> > thread that is not a Lisp thread (i.e. an OS thread created by the
> module).
> > That's exactly one of the undefined behavior situations that the
> assertions
> > are meant to prevent.
>
> Right.  And that's why dereferencing a potentially NULL pointer is IMO
> something we should avoid doing.
>

Yes, but in general we can't avoid that. It's a module bug, but we can't
protect against all module bugs. The assertions are there for module
developers to catch these bugs before releasing a module.


>
> I also think that we should try replacing eassert in this case with a
> function that doesn't crash Emacs, only errors out of the offending
> module, since a faulty module ideally shouldn't crash the entire Emacs
> session.  But that might be hard to accomplish.  In any case, note
> that eassert compiles to nothing in the production build.
>

Yes, that's why in the other thread I've implemented the module assertions,
which are enabled on the command line and reliably crash Emacs.
Other ways of error reporting without crashing are unfortunately not
possible without major changes to the module API.

[-- Attachment #2: Type: text/html, Size: 4520 bytes --]

      reply	other threads:[~2017-06-12 15:04 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-22 15:24 [PATCH] Support threads in modules Philipp Stephani
2017-04-22 19:09 ` Eli Zaretskii
2017-04-22 19:21   ` Philipp Stephani
2017-04-22 19:49     ` Eli Zaretskii
2017-04-22 20:05       ` Philipp Stephani
2017-04-22 20:14         ` Eli Zaretskii
2017-04-23  6:14           ` John Wiegley
2017-04-23 12:40             ` Stefan Monnier
2017-04-26  5:23               ` Eli Zaretskii
2017-04-23 15:54             ` Philipp Stephani
2017-04-23 15:52           ` Philipp Stephani
2017-04-26  5:31             ` Eli Zaretskii
2017-06-10 11:38               ` Philipp Stephani
2017-06-10 12:38                 ` Eli Zaretskii
2017-06-10 19:58                   ` Philipp Stephani
2017-06-11 13:25                     ` Philipp Stephani
2017-06-11 14:54                       ` Eli Zaretskii
2017-06-11 17:12                         ` Philipp Stephani
2017-06-11 15:01                     ` Eli Zaretskii
2017-06-12 15:04                       ` Philipp Stephani [this message]

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to='CAArVCkSRH4aVzf=oCiFv73pxKQqJ+Yh53NiCnSPUfKMbZ45QSg@mail.gmail.com' \
    --to=p.stephani2@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=phst@google.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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).