[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: semantics of thread-signal
From: |
Noam Postavsky |
Subject: |
Re: semantics of thread-signal |
Date: |
Sun, 11 Dec 2016 21:06:38 -0500 |
On Sun, Dec 11, 2016 at 8:21 PM, Juliusz Chroboczek <address@hidden> wrote:
>>> I assumed this to mean that the condition will only be delivered when
>>> one of these functions is called, but your comment seems to imply that
>>> it's meant to deliver the condition as soon as possible.
>
>> My interpretation is that mutex-lock (and the others) block the thread
>> until something happens (e.g., another thread calls mutex-unlock), and
>> thread-signal is another thing which can end the blocking (and also
>> trigger a signal when the thread next runs).
>
> Reasonable enough. Perhaps somebody could clarify the docs?
>
Something like this?
--- i/doc/lispref/threads.texi
+++ w/doc/lispref/threads.texi
@@ -82,9 +82,11 @@ Basic Thread Functions
@defun thread-signal thread error-symbol data
Like @code{signal} (@pxref{Signaling Errors}), but the signal is
delivered in the thread @var{thread}. If @var{thread} is the current
-thread, then this just calls @code{signal} immediately.
address@hidden will cause a thread to exit a call to
address@hidden, @code{condition-wait}, or @code{thread-join}.
+thread, then this just calls @code{signal} immediately. Otherwise,
address@hidden will receive the signal as soon as it becomes current.
+If @var{thread} was blocked by a call to @code{mutex-lock},
address@hidden, or @code{thread-join}; @code{thread-signa} will
+unblock it.
@end defun
>
> The manual says:
>
> However, the Emacs thread support has been designed in a way to
> later allow more fine-grained concurrency, and correct programs
> should not rely on cooperative threading.
>
> So if thread-signal can be delivered asynchronously, this will cause
> trouble when Emacs moves to kernel threads.
Hmm, if we really want to be safe for preemptive threads, we would
probably need to add some way to block asynch signals, and
unwind-protect would use that during the unwind forms. It would also
be needed between calling make-foo and setting the value of foo.