From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#36609: 27.0.50; Possible race-condition in threading implementation Date: Sun, 20 Jun 2021 14:39:31 +0300 Message-ID: <837diovk7g.fsf@gnu.org> References: <87muhks3b5.fsf@hochschule-trier.de> <87fsxv8182.fsf@dick> <83wnr7gdd8.fsf@gnu.org> <875yyqg66k.fsf@dick> <83k0n6hjym.fsf@gnu.org> <87wnr2lnsj.fsf@dick> <83h7i6cj3z.fsf@gnu.org> <87bl8e2aya.fsf@dick> <8335tpdcq9.fsf@gnu.org> <87y2bhepl2.fsf@dick> <83y2bhbw14.fsf@gnu.org> <87czstmmgi.fsf@dick> <83zgvx9c0o.fsf@gnu.org> <83y2b5vj04.fsf@gnu.org> <87sg1dwttg.fsf@dick> <83tultvf1o.fsf@gnu.org> <87o8c1wocf.fsf@dick> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9460"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 36609@debbugs.gnu.org To: dick.r.chiang@gmail.com Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jun 20 13:40:22 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1luvoL-0002FA-RL for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 20 Jun 2021 13:40:21 +0200 Original-Received: from localhost ([::1]:60154 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luvoK-0004VO-7P for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 20 Jun 2021 07:40:20 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54182) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luvo3-0004Uz-LT for bug-gnu-emacs@gnu.org; Sun, 20 Jun 2021 07:40:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49869) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1luvo2-0004RB-Kn for bug-gnu-emacs@gnu.org; Sun, 20 Jun 2021 07:40:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1luvo2-0001Zm-Gx for bug-gnu-emacs@gnu.org; Sun, 20 Jun 2021 07:40:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 20 Jun 2021 11:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 36609 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: fixed Original-Received: via spool by 36609-submit@debbugs.gnu.org id=B36609.16241891676011 (code B ref 36609); Sun, 20 Jun 2021 11:40:02 +0000 Original-Received: (at 36609) by debbugs.gnu.org; 20 Jun 2021 11:39:27 +0000 Original-Received: from localhost ([127.0.0.1]:33182 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1luvnT-0001Yt-Cr for submit@debbugs.gnu.org; Sun, 20 Jun 2021 07:39:27 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:56402) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1luvnS-0001Yh-EG for 36609@debbugs.gnu.org; Sun, 20 Jun 2021 07:39:26 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:36962) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luvnN-0003uf-4c; Sun, 20 Jun 2021 07:39:21 -0400 Original-Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:4156 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luvnM-0000fV-LW; Sun, 20 Jun 2021 07:39:20 -0400 In-Reply-To: <87o8c1wocf.fsf@dick> (dick.r.chiang@gmail.com) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:208789 Archived-At: > From: dick.r.chiang@gmail.com > Cc: 36609@debbugs.gnu.org > Date: Sat, 19 Jun 2021 17:12:32 -0400 > > "Suggest" or "Provide"? > > If the former, well, my recalcitrance should be your answer. > > If the latter, sure Thanks, please try the patch below. > although if you've written the patch, then running my MREs would be > epsilon more effort. You have a use case and wrote code with which you are familiar, so you are in a better position to test it. Moreover, I don't have access to a system where these problems could happen, so it's far from epsilon effort for me. diff --git a/src/xgselect.c b/src/xgselect.c index 0d91d55bad..9a90670b0f 100644 --- a/src/xgselect.c +++ b/src/xgselect.c @@ -34,12 +34,27 @@ static GMainContext *glib_main_context; void release_select_lock (void) { +#if GNUC_PREREQ (4, 7, 0) + if (__atomic_sub_fetch (&threads_holding_glib_lock, 1, __ATOMIC_ACQ_REL)) + g_main_context_release (glib_main_context); +#else if (--threads_holding_glib_lock == 0) g_main_context_release (glib_main_context); +#endif } static void acquire_select_lock (GMainContext *context) { +#if GNUC_PREREQ (4, 7, 0) + if (__atomic_fetch_add (&threads_holding_glib_lock, 1, __ATOMIC_ACQ_REL) == 0) + { + glib_main_context = context; + while (!g_main_context_acquire (context)) + { + /* Spin. */ + } + } +#else if (threads_holding_glib_lock++ == 0) { glib_main_context = context; @@ -48,6 +63,7 @@ static void acquire_select_lock (GMainContext *context) /* Spin. */ } } +#endif } /* `xg_select' is a `pselect' replacement. Why do we need a separate function?