From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Derek Davies Newsgroups: gmane.emacs.devel Subject: Re: Why does this thread code crash my emacs? Date: Fri, 15 Oct 2021 18:17:26 -0400 Message-ID: <87bl3qrkzt.fsf@ddavies.net> References: <87pms6jmuk.fsf@ddavies.net> <83r1cmi03z.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="2674"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.2.0; emacs 26.3 Cc: Derek Davies , emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Oct 16 00:18:53 2021 Return-path: Envelope-to: ged-emacs-devel@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 1mbVXP-0000VT-KT for ged-emacs-devel@m.gmane-mx.org; Sat, 16 Oct 2021 00:18:51 +0200 Original-Received: from localhost ([::1]:33300 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mbVXO-00049v-4B for ged-emacs-devel@m.gmane-mx.org; Fri, 15 Oct 2021 18:18:50 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49400) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mbVWQ-0003Oa-An for emacs-devel@gnu.org; Fri, 15 Oct 2021 18:17:50 -0400 Original-Received: from gateway31.websitewelcome.com ([192.185.143.35]:18855) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mbVWO-0007E2-D7 for emacs-devel@gnu.org; Fri, 15 Oct 2021 18:17:50 -0400 Original-Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway31.websitewelcome.com (Postfix) with ESMTP id 01C481E00F4 for ; Fri, 15 Oct 2021 17:17:28 -0500 (CDT) Original-Received: from gator4032.hostgator.com ([192.185.4.43]) by cmsmtp with SMTP id bVW3mBYzetL6ebVW3mRxl0; Fri, 15 Oct 2021 17:17:27 -0500 X-Authority-Reason: nr=8 Original-Received: from c-65-96-169-180.hsd1.ma.comcast.net ([65.96.169.180]:57482 helo=masha.ddavies.net) by gator4032.hostgator.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mbVW3-000Dd2-Ag; Fri, 15 Oct 2021 17:17:27 -0500 In-reply-to: <83r1cmi03z.fsf@gnu.org> X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4032.hostgator.com X-AntiAbuse: Original Domain - gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - ddavies.net X-BWhitelist: no X-Source-IP: 65.96.169.180 X-Source-L: No X-Exim-ID: 1mbVW3-000Dd2-Ag X-Source-Sender: c-65-96-169-180.hsd1.ma.comcast.net (masha.ddavies.net) [65.96.169.180]:57482 X-Source-Auth: ddavies@ddavies.net X-Email-Count: 2 X-Source-Cap: ZGRhdmllcztkZGF2aWVzO2dhdG9yNDAzMi5ob3N0Z2F0b3IuY29t X-Local-Domain: yes Received-SPF: pass client-ip=192.185.143.35; envelope-from=ddavies@ddavies.net; helo=gateway31.websitewelcome.com X-Spam_score_int: 0 X-Spam_score: -0.0 X-Spam_bar: / X-Spam_report: (-0.0 / 5.0 requ) RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:277143 Archived-At: Eli Zaretskii writes: >> From: Derek Davies >> Date: Fri, 15 Oct 2021 12:04:35 -0400 >> >> Working with the thread-signal example from: https://emacs-berlin.org/thread-safe-tramp-2018-09.html >> >> it works for me as given, but when I run hanoi instead of sleeping in >> thread2 my emacs consistently crashes (back to command line from which >> it was invoked). >> >> I've been poking at it, but without much insight -- does anyone know >> what I or hanoi or threading is doing wrong? > > You currently cannot signal a thread that is waiting for input (hanoi > waits for input inside sit-for), because Emacs doesn't (yet) know how > to recover from signals in that state. > > IOW, this is a limitation of the current implementation that is more > visible when signaling threads than when there's only one (main) > thread. Just for fun, and since the wise monks of hanoi wrapped sit-for in hanoi-sit-for, I seem to be able to get away with the following hack. (defun my-thread1 () (sleep-for 10) (thread-signal thread2 'error '())) (defun my-thread2 () (condition-case err (let ((ex-fx (symbol-function 'hanoi-sit-for))) (fset 'hanoi-sit-for #'(lambda (secs &optional nodisp) (sleep-for secs) (or nodisp (redisplay)) t)) (unwind-protect (hanoi 11) (progn (fset 'hanoi-sit-for ex-fx) (message "Done")))) (error (message "Thread %s signaled by `%s'" (current-thread) err)))) (setq thread1 (make-thread #'my-thread1 "my thread 1")) (message "my thread1 %S" thread1) (setq thread2 (make-thread #'my-thread2 "my thread 2"))) (message "my thread2 %S" thread2) Thanks for the attention to my question! Derek