unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Po Lu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Tom Gillespie <tgbugs@gmail.com>
Cc: 56487@debbugs.gnu.org
Subject: bug#56487: xgselect race condition leading to abort when USE_GTK not defined
Date: Mon, 11 Jul 2022 09:53:22 +0800	[thread overview]
Message-ID: <871qus1kkt.fsf@yahoo.com> (raw)
In-Reply-To: <CA+G3_PM8-aF+OdLrBg+PPFOmvCMYcVr-VHsASRt0xe4b9E5FYQ@mail.gmail.com> (Tom Gillespie's message of "Sun, 10 Jul 2022 14:05:58 -0700")

Tom Gillespie <tgbugs@gmail.com> writes:

> From e120751b9de79be521f490f8c2f99597868b3208 Mon Sep 17 00:00:00 2001
> From: Tom Gillespie <tgbugs@gmail.com>
> Date: Tue, 5 Jul 2022 13:43:25 -0700
> Subject: [PATCH] xgselect.c: avoid race condition leading to abort
>
> xgselect.c (xg_select): Remove ifdefs that were previously USE_GTK
> specific to be unconditional. This prevents a race condition caused by
> a call to release_select_lock from triggering when configuring Emacs
> with any toolkit other than gtk.
>
> xgselect.c (release_select_lock): Add a branch to check whether
> threads_holding_glib_lock has gone negative, and if so, restore to zero.
> In the case where there are multiple threads, threads_holding_glib_lock
> could become and stay negative, prevending g_main_context_release from
> ever being called, even when it should have been.
>
> As far as I can tell the way that the thread.c and xgselect.c code was
> written was with the intention of avoiding additional locks. This means
> that this code is exquisitely senstivie to slight changes in timing. A
> comment in thread.c has been added at one location where this happens.
>
> It is entirely possible that the removal of the ifdefs branching on
> USE_GTK resolves this issue by slightly changing the timings when
> using other/no toolkits so that the abort does not trigger. In all
> cases aborts can be induced by adding something like fputs in thread.c
> at the location of the new comment.
>
> For the record, the abort behavior is not present in Emacs 27, and was
> introduced by 9c62ffb08262c82b7e38e6eb5767f2087424aa47 (the bisect was
> quite a pain, so hopefully no one ever needs to do it again).

Thanks.  The commit message does not really comply with our style,
however.  The ChangeLog entries should look like this instead:


* src/xgselect.c (xg_select): Remove ifdefs that were previously
USE_GTK specific to be unconditional. This prevents a race
condition caused by a call to release_select_lock from
triggering when configuring Emacs with any toolkit other than
GTK.
(release_select_lock): Add a branch to check whether
threads_holding_glib_lock has gone negative, and if so, restore
to zero.  In the case where there are multiple threads,
threads_holding_glib_lock could become and stay negative,
prevending g_main_context_release from ever being called, even
when it should have been.


You can use C-c C-w inside a *vc-log* buffer to generate an
appropriately formatted commit message.





  reply	other threads:[~2022-07-11  1:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-10 21:05 bug#56487: xgselect race condition leading to abort when USE_GTK not defined Tom Gillespie
2022-07-11  1:53 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-07-11  2:50   ` Tom Gillespie
2022-07-11  3:13     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-07-11  3:40       ` Tom Gillespie
2022-07-11 10:16         ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-07-11 16:09           ` Tom Gillespie
2022-07-12  2:03             ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-07-12  2:20               ` Tom Gillespie
2022-07-12 12:44                 ` Eli Zaretskii
2022-07-15  5:09                   ` Tom Gillespie
2023-09-07 18:30                   ` Stefan Kangas

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=871qus1kkt.fsf@yahoo.com \
    --to=bug-gnu-emacs@gnu.org \
    --cc=56487@debbugs.gnu.org \
    --cc=luangruo@yahoo.com \
    --cc=tgbugs@gmail.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).