all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Derek Davies <ddavies@ddavies.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: Derek Davies <ddavies@ddavies.net>, emacs-devel@gnu.org
Subject: Re: Why does this thread code crash my emacs?
Date: Fri, 15 Oct 2021 18:17:26 -0400	[thread overview]
Message-ID: <87bl3qrkzt.fsf@ddavies.net> (raw)
In-Reply-To: <83r1cmi03z.fsf@gnu.org>


Eli Zaretskii <eliz@gnu.org> writes:

>> From: Derek Davies <ddavies@ddavies.net>
>> 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



  reply	other threads:[~2021-10-15 22:17 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-15 16:04 Why does this thread code crash my emacs? Derek Davies
2021-10-15 18:45 ` dick
2021-10-15 19:17   ` Eli Zaretskii
2021-10-15 19:56     ` dick
2021-10-16  7:06       ` tomas
2021-10-16  7:19       ` Eli Zaretskii
2021-10-16 10:53         ` dick
2021-10-16 11:12           ` Eli Zaretskii
2021-10-15 19:01 ` Eli Zaretskii
2021-10-15 22:17   ` Derek Davies [this message]
2021-10-16  0:08     ` dick
2021-10-16 11:51   ` Eli Zaretskii

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bl3qrkzt.fsf@ddavies.net \
    --to=ddavies@ddavies.net \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.