From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: dick.r.chiang@gmail.com Newsgroups: gmane.emacs.bugs Subject: bug#36609: 27.0.50; Possible race-condition in threading implementation Date: Sun, 20 Jun 2021 10:01:37 -0400 Message-ID: <87fsxcws72.fsf@dick> 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> <837diovk7g.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14750"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.14 (Gnus v5.14pre) Emacs/28.0.50 (gnu/linux) Cc: 36609@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jun 20 16:02:09 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 1luy1Z-0003i9-Kk for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 20 Jun 2021 16:02:09 +0200 Original-Received: from localhost ([::1]:33892 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luy1Y-0000pl-Lt for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 20 Jun 2021 10:02:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41092) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luy1T-0000pd-7z for bug-gnu-emacs@gnu.org; Sun, 20 Jun 2021 10:02:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51430) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1luy1S-0006QJ-T7 for bug-gnu-emacs@gnu.org; Sun, 20 Jun 2021 10:02:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1luy1S-0005GC-HZ for bug-gnu-emacs@gnu.org; Sun, 20 Jun 2021 10:02:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: dick.r.chiang@gmail.com Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 20 Jun 2021 14:02: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.162419770720199 (code B ref 36609); Sun, 20 Jun 2021 14:02:02 +0000 Original-Received: (at 36609) by debbugs.gnu.org; 20 Jun 2021 14:01:47 +0000 Original-Received: from localhost ([127.0.0.1]:34743 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1luy1D-0005Fj-AC for submit@debbugs.gnu.org; Sun, 20 Jun 2021 10:01:47 -0400 Original-Received: from mail-qk1-f178.google.com ([209.85.222.178]:43634) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1luy1A-0005FW-VQ for 36609@debbugs.gnu.org; Sun, 20 Jun 2021 10:01:46 -0400 Original-Received: by mail-qk1-f178.google.com with SMTP id j62so23632729qke.10 for <36609@debbugs.gnu.org>; Sun, 20 Jun 2021 07:01:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=d29ynUKRA/9ZTJSxQg09rXyfp+lCfQhpsWgvUa6CU5g=; b=PpjTtgkoY/z3lmc6Kv350nG2CWK1DmA53JzSnXce6Ss7emwDbw5yZNbnwGwxS6c00K KiaclqLnUa6DsBYfVI1N12feKcIgk8Rndqy11CmavCjXyzXqiNPZwVBjEEVPsgJz/1L8 X1Ba7o9Gpe7+L/4LLXsetjsjJdAMvcCprMqKM2yvfDTWvIJahHycSx2YnIy2OtWioxt5 uvdw8gZ0qvptw+ePQmgY1E3DcHksBVPYB0Mjiz+14Va2VXV2mpDlqEmr/YKvsczR2kyS CgrNX9KXvDakF55haSNjboXvClVbjfO2X5uokhjqDE/oW1Z1oud9yISKfYB4lOsN2AEU upfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=d29ynUKRA/9ZTJSxQg09rXyfp+lCfQhpsWgvUa6CU5g=; b=XdaojH3BUWqK7R2GUx4Su54UbDNQ0/1MYSUrhXuSjEZ+PhGJedqOYMad9tcrKPLe0g m/RE6JXtREGNPlDyPi1APyI9Ug1FXsFioGZ6+Sf8DoAp4eELZiQqUpw99oNXOPFjjzsr AkaF9JfGf+upAs8B7XnSpLONWJN571+DxMMUFyZ+r/FMREfiDCz7Tp2VYdE8qotXpD/4 b8uhvrIXVqPLca9967MYcnRkUi1s2l+vu+3JSzZBOIIOTbNPt5tbg6/fKldNUwK0SnAj UTf4Bilj+hnXpKpK1+ghJO5pT7HQTaJxHME6h/IM/QWziSxxfyJuUniMtL5vqiXU5O95 HryQ== X-Gm-Message-State: AOAM531afR5eldhrm6YFrW9qHQKeSmsRxi0Kuw9/VqdTK0XN7Dlfyt4G xCSKhJX8+UeqfgpphsLsj+M= X-Google-Smtp-Source: ABdhPJwf52HOC3YNWLRTq6BSfdXyPyBkjYSYIbnFUEJXAgUFQfNv7xWmWjnbjrBVBRX+J9QGLS1L8Q== X-Received: by 2002:a05:620a:29d3:: with SMTP id s19mr18237743qkp.434.1624197699164; Sun, 20 Jun 2021 07:01:39 -0700 (PDT) Original-Received: from localhost (pool-71-190-212-171.nycmny.fios.verizon.net. [71.190.212.171]) by smtp.gmail.com with ESMTPSA id 18sm4798443qkk.103.2021.06.20.07.01.38 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 20 Jun 2021 07:01:38 -0700 (PDT) In-Reply-To: <837diovk7g.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 20 Jun 2021 14:39:31 +0300") 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:208792 Archived-At: Yes! If you just add a negation to the __atomic_sub_fetch call, this passes all the MREs. It's not clear how you want to deal with the #else GNUC_PREREQ (4, 7, 0). >>>>> "EZ" == Eli Zaretskii writes: >> 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 EZ> Thanks, please try the patch below. >> although if you've written the patch, then running my MREs would be epsilon >> more effort. EZ> You have a use case and wrote code with which you are familiar, so you are EZ> in a better position to test it. Moreover, I don't have access to a EZ> system where these problems could happen, so it's far from epsilon effort EZ> for me. EZ> diff --git a/src/xgselect.c b/src/xgselect.c EZ> index 0d91d55bad..9a90670b0f 100644 EZ> --- a/src/xgselect.c EZ> +++ b/src/xgselect.c EZ> @@ -34,12 +34,27 @@ static GMainContext *glib_main_context; EZ> void release_select_lock (void) EZ> { EZ> +#if GNUC_PREREQ (4, 7, 0) EZ> + if (__atomic_sub_fetch (&threads_holding_glib_lock, 1, __ATOMIC_ACQ_REL)) EZ> + g_main_context_release (glib_main_context); EZ> +#else EZ> if (--threads_holding_glib_lock == 0) EZ> g_main_context_release (glib_main_context); EZ> +#endif EZ> } EZ> static void acquire_select_lock (GMainContext *context) EZ> { EZ> +#if GNUC_PREREQ (4, 7, 0) EZ> + if (__atomic_fetch_add (&threads_holding_glib_lock, 1, __ATOMIC_ACQ_REL) == 0) EZ> + { EZ> + glib_main_context = context; EZ> + while (!g_main_context_acquire (context)) EZ> + { EZ> + /* Spin. */ EZ> + } EZ> + } EZ> +#else EZ> if (threads_holding_glib_lock++ == 0) EZ> { EZ> glib_main_context = context; EZ> @@ -48,6 +63,7 @@ static void acquire_select_lock (GMainContext *context) EZ> /* Spin. */ EZ> } EZ> } EZ> +#endif EZ> } EZ> /* `xg_select' is a `pselect' replacement. Why do we need a separate EZ> function?