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, 06 Jun 2021 19:35:31 +0300 Message-ID: <83wnr7gdd8.fsf@gnu.org> References: <87muhks3b5.fsf@hochschule-trier.de> <87fsxv8182.fsf@dick> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10001"; mail-complaints-to="usenet@ciao.gmane.io" Cc: larsi@gnus.org, politza@hochschule-trier.de, pipcet@gmail.com, 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 06 18:36:13 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 1lpvkz-0002OU-Dm for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 06 Jun 2021 18:36:13 +0200 Original-Received: from localhost ([::1]:59108 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lpvky-0006Lu-FU for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 06 Jun 2021 12:36:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33034) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lpvko-0006Kq-QE for bug-gnu-emacs@gnu.org; Sun, 06 Jun 2021 12:36:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42224) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lpvko-00040h-JX for bug-gnu-emacs@gnu.org; Sun, 06 Jun 2021 12:36:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lpvko-0007jv-Ge for bug-gnu-emacs@gnu.org; Sun, 06 Jun 2021 12:36: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, 06 Jun 2021 16:36: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.162299734529728 (code B ref 36609); Sun, 06 Jun 2021 16:36:02 +0000 Original-Received: (at 36609) by debbugs.gnu.org; 6 Jun 2021 16:35:45 +0000 Original-Received: from localhost ([127.0.0.1]:53770 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lpvkW-0007jQ-NC for submit@debbugs.gnu.org; Sun, 06 Jun 2021 12:35:44 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:39358) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lpvkU-0007jB-BD for 36609@debbugs.gnu.org; Sun, 06 Jun 2021 12:35:43 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:54066) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lpvkN-0003nv-NM; Sun, 06 Jun 2021 12:35:35 -0400 Original-Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:3922 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 1lpvkN-0003wU-9q; Sun, 06 Jun 2021 12:35:35 -0400 In-Reply-To: <87fsxv8182.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:208138 Archived-At: > From: dick.r.chiang@gmail.com > Cc: Pip Cet , larsi@gnus.org, 36609@debbugs.gnu.org, > Eli Zaretskii > Date: Sun, 06 Jun 2021 11:25:01 -0400 > > #1. Want to revert commit 9c62ffb This will bring back bug#36609, so we cannot do that without discussing first why you think that commit was wrong. > #2. Fails on tip of master, succeeds after patch in #1. Please explain what does "fails" mean, and why do you think the above commit is the culprit. (A much simpler test case will be appreciated, btw.) > Fails not necessarily because xgselect.c is wrong, but rather because > channel-recv blocks on a mutex before channel-send can get its act together. You mean, in this code: (let ((channel (make-channel 1))) (make-thread (lambda nil (channel-send (car channel) 42)) "produce") (channel-recv (cdr channel)) (ignore-errors (enable-command 'list-threads)) (call-interactively #'list-threads)) ? Here, channel-send is called by a new thread, created by make-thread. In this code, it is _expected_ that channel-recv will be called (by the main thread) _before_ channel-send is called by the new thread, because make-thread creates a thread, but the newly created thread doesn't run until it can acquire the global lock. Meanwhile, the main thread continues running and calls channel-recv. The new thread will not begin running, AFAIU, until the main thread calls condition-wait inside channel-recv. By "blocks on a mutex", did you mean that channel-recv blocks trying to acquire the mutex here: (cl-defgeneric channel-recv ((sink channel-terminal)) (with-mutex (oref sink mutex) <<<<<<<<<<<<<<<<<<<<<<<<<< (with-slots (condition msg-queue) sink If so, which thread holds that mutex at this point? > #4. What #3 probably intended, succeeds after patch in #1. Yes, race conditions can be solved by using sleep-for, but that's not really a clean solution, at least not in my book.