[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why does this thread code crash my emacs?

From: Derek Davies
Subject: Re: Why does this thread code crash my emacs?
Date: Fri, 15 Oct 2021 18:17:26 -0400
User-agent: mu4e 1.2.0; emacs 26.3

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))
            (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!


reply via email to

[Prev in Thread] Current Thread [Next in Thread]