From: Michael Albinus <michael.albinus@gmx.de>
To: Eli Zaretskii <eliz@gnu.org>
Cc: gazally@runbox.com, 32502@debbugs.gnu.org
Subject: bug#32502: 27.0.50; Tramp; C-g during asynchronous remote find-file kills Emacs
Date: Thu, 30 Aug 2018 18:48:19 +0200 [thread overview]
Message-ID: <87h8jb7qcs.fsf@gmx.de> (raw)
In-Reply-To: <87h8jcvtt1.fsf@gmx.de> (Michael Albinus's message of "Thu, 30 Aug 2018 15:59:54 +0200")
[-- Attachment #1: Type: text/plain, Size: 935 bytes --]
Michael Albinus <michael.albinus@gmx.de> writes:
>>> I'm just changing thread-signal such a way that it ignores silently
>>> signals sent to the main thread. Shall I implement this event injection
>>> instead?
>>
>> I don't know. I guess it depends on how important is it to show the
>> errors nicely. You could leave signals for now and use the events
>> idea later as an enhancement.
>
> I will see how easy it is. I have experience with dbus-event and
> file-notify-event; it shouldn't too hard for me to implement thread-event.
>
>>> And what shall be done with this event in the main thread? Just writing
>>> an error message, or some kind of handling?
>>
>> Yes, displaying a message would be a good starting point, I think.
>
> Since special events have their own handler, it will be simple to change
> later. Will start with echoing the error message.
Appended is a first implementation. Comments?
Best regards, Michael.
[-- Attachment #2: Type: text/plain, Size: 5428 bytes --]
diff --git a/doc/lispref/threads.texi b/doc/lispref/threads.texi
index 58a3a918ef..9830198411 100644
--- a/doc/lispref/threads.texi
+++ b/doc/lispref/threads.texi
@@ -88,14 +88,8 @@ Basic Thread Functions
@code{condition-wait}, or @code{thread-join}; @code{thread-signal}
will unblock it.
-Since signal handlers in Emacs are located in the main thread, a
-signal must be propagated there in order to become visible. The
-second @code{signal} call let the thread die:
-
-@example
-(thread-signal main-thread 'error data)
-(signal 'error data)
-@end example
+If @var{thread} is the main thread, the signal is not propagated
+there. Instead, it is shown as message in the main thread.
@end defun
@defun thread-yield
diff --git a/src/keyboard.c b/src/keyboard.c
index 7fafb41fcc..008d3b9d7c 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -2827,6 +2827,9 @@ read_char (int commandflag, Lisp_Object map,
#endif
#ifdef USE_FILE_NOTIFY
|| EQ (XCAR (c), Qfile_notify)
+#endif
+#ifdef THREADS_ENABLED
+ || EQ (XCAR (c), Qthread_event)
#endif
|| EQ (XCAR (c), Qconfig_changed_event))
&& !end_time)
@@ -3739,7 +3742,7 @@ kbd_buffer_get_event (KBOARD **kbp,
}
#endif /* subprocesses */
-#if !defined HAVE_DBUS && !defined USE_FILE_NOTIFY
+#if !defined HAVE_DBUS && !defined USE_FILE_NOTIFY && !defined THREADS_ENABLED
if (noninteractive
/* In case we are running as a daemon, only do this before
detaching from the terminal. */
@@ -3750,7 +3753,7 @@ kbd_buffer_get_event (KBOARD **kbp,
*kbp = current_kboard;
return obj;
}
-#endif /* !defined HAVE_DBUS && !defined USE_FILE_NOTIFY */
+#endif /* !defined HAVE_DBUS && !defined USE_FILE_NOTIFY && !defined THREADS_ENABLED */
/* Wait until there is input available. */
for (;;)
@@ -3900,6 +3903,9 @@ kbd_buffer_get_event (KBOARD **kbp,
#ifdef HAVE_DBUS
case DBUS_EVENT:
#endif
+#ifdef THREADS_ENABLED
+ case THREAD_EVENT:
+#endif
#ifdef HAVE_XWIDGETS
case XWIDGET_EVENT:
#endif
@@ -5983,6 +5989,13 @@ make_lispy_event (struct input_event *event)
}
#endif /* HAVE_DBUS */
+#ifdef THREADS_ENABLED
+ case THREAD_EVENT:
+ {
+ return Fcons (Qthread_event, event->arg);
+ }
+#endif /* THREADS_ENABLED */
+
#ifdef HAVE_XWIDGETS
case XWIDGET_EVENT:
{
@@ -11078,6 +11091,10 @@ syms_of_keyboard (void)
DEFSYM (Qdbus_event, "dbus-event");
#endif
+#ifdef THREADS_ENABLED
+ DEFSYM (Qthread_event, "thread-event");
+#endif
+
#ifdef HAVE_XWIDGETS
DEFSYM (Qxwidget_event, "xwidget-event");
#endif
@@ -11929,6 +11946,12 @@ keys_of_keyboard (void)
"dbus-handle-event");
#endif
+#ifdef THREADS_ENABLED
+ /* Define a special event which is raised for thread signals. */
+ initial_define_lispy_key (Vspecial_event_map, "thread-event",
+ "thread-handle-event");
+#endif
+
#ifdef USE_FILE_NOTIFY
/* Define a special event which is raised for notification callback
functions. */
diff --git a/src/termhooks.h b/src/termhooks.h
index 160bd2f480..8b5f648b43 100644
--- a/src/termhooks.h
+++ b/src/termhooks.h
@@ -222,6 +222,10 @@ enum event_kind
, DBUS_EVENT
#endif
+#ifdef THREADS_ENABLED
+ , THREAD_EVENT
+#endif
+
, CONFIG_CHANGED_EVENT
#ifdef HAVE_NTGUI
diff --git a/src/thread.c b/src/thread.c
index 1c73d93865..0234f65e02 100644
--- a/src/thread.c
+++ b/src/thread.c
@@ -25,6 +25,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
#include "process.h"
#include "coding.h"
#include "syssignal.h"
+#include "keyboard.h"
static struct thread_state main_thread;
@@ -34,7 +35,6 @@ static struct thread_state *all_threads = &main_thread;
static sys_mutex_t global_lock;
-extern int poll_suppress_count;
extern volatile int interrupt_input_blocked;
\f
@@ -863,7 +863,8 @@ DEFUN ("thread-signal", Fthread_signal, Sthread_signal, 3, 3, 0,
This acts like `signal', but arranges for the signal to be raised
in THREAD. If THREAD is the current thread, acts just like `signal'.
This will interrupt a blocked call to `mutex-lock', `condition-wait',
-or `thread-join' in the target thread. */)
+or `thread-join' in the target thread.
+Signals to the main thread are ignored quietly. */)
(Lisp_Object thread, Lisp_Object error_symbol, Lisp_Object data)
{
struct thread_state *tstate;
@@ -874,13 +875,29 @@ or `thread-join' in the target thread. */)
if (tstate == current_thread)
Fsignal (error_symbol, data);
- /* What to do if thread is already signaled? */
- /* What if error_symbol is Qnil? */
- tstate->error_symbol = error_symbol;
- tstate->error_data = data;
+ if (main_thread_p (tstate))
+ {
+ /* Construct an event. */
+ struct input_event event;
+ EVENT_INIT (event);
+ event.kind = THREAD_EVENT;
+ event.frame_or_window = Qnil;
+ event.arg = list3 (Fcurrent_thread (), error_symbol, data);
+
+ /* Store it into the input event queue. */
+ kbd_buffer_store_event (&event);
+ }
+
+ else
+ {
+ /* What to do if thread is already signaled? */
+ /* What if error_symbol is Qnil? */
+ tstate->error_symbol = error_symbol;
+ tstate->error_data = data;
- if (tstate->wait_condvar)
- flush_stack_call_func (thread_signal_callback, tstate);
+ if (tstate->wait_condvar)
+ flush_stack_call_func (thread_signal_callback, tstate);
+ }
return Qnil;
}
next prev parent reply other threads:[~2018-08-30 16:48 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-22 18:19 bug#32502: 27.0.50; Tramp; C-g during asynchronous remote find-file kills Emacs Gemini Lasswell
2018-08-22 18:46 ` Eli Zaretskii
2018-08-22 19:08 ` Eli Zaretskii
2018-08-22 19:23 ` Michael Albinus
2018-08-25 10:53 ` Michael Albinus
2018-08-25 12:42 ` Eli Zaretskii
2018-08-25 15:52 ` Michael Albinus
2018-08-25 16:07 ` Eli Zaretskii
2018-08-26 13:50 ` Gemini Lasswell
2018-08-30 9:24 ` Michael Albinus
2018-08-30 13:23 ` Eli Zaretskii
2018-08-30 13:28 ` Michael Albinus
2018-08-25 21:53 ` Gemini Lasswell
2018-08-26 14:12 ` Eli Zaretskii
2018-08-30 7:19 ` Michael Albinus
2018-08-30 12:34 ` Michael Albinus
2018-08-29 16:01 ` Michael Albinus
2018-08-29 16:23 ` Eli Zaretskii
2018-08-29 16:46 ` Michael Albinus
2018-08-29 17:03 ` Eli Zaretskii
2018-08-29 17:15 ` Michael Albinus
2018-08-29 20:22 ` Michael Albinus
2018-08-29 20:57 ` Michael Albinus
2018-08-30 2:36 ` Eli Zaretskii
2018-08-30 7:09 ` Michael Albinus
2018-08-30 13:18 ` Eli Zaretskii
2018-08-30 13:32 ` Michael Albinus
2018-08-30 13:51 ` Eli Zaretskii
2018-08-30 13:59 ` Michael Albinus
2018-08-30 16:48 ` Michael Albinus [this message]
2018-08-30 17:44 ` Eli Zaretskii
2018-08-30 19:30 ` Michael Albinus
2018-09-02 17:58 ` Michael Albinus
2018-09-02 20:03 ` Gemini Lasswell
2018-09-02 20:50 ` Michael Albinus
2018-08-30 19:29 ` Gemini Lasswell
2018-08-30 19:37 ` Michael Albinus
2018-08-31 6:52 ` Eli Zaretskii
2018-08-31 15:07 ` Gemini Lasswell
2018-08-31 17:45 ` Eli Zaretskii
2018-08-22 21:12 ` Gemini Lasswell
2018-08-23 14:01 ` 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=87h8jb7qcs.fsf@gmx.de \
--to=michael.albinus@gmx.de \
--cc=32502@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=gazally@runbox.com \
/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.