From: Eli Zaretskii <eliz@gnu.org>
To: Tino Calancha <tino.calancha@gmail.com>,
Ken Raeburn <raeburn@raeburn.org>
Cc: 25247@debbugs.gnu.org
Subject: bug#25247: 26.0.50; Concurrency crashes
Date: Thu, 22 Dec 2016 19:28:48 +0200 [thread overview]
Message-ID: <83a8bn27qn.fsf@gnu.org> (raw)
In-Reply-To: <87bmw4w9i2.fsf@gmail.com> (message from Tino Calancha on Thu, 22 Dec 2016 19:20:21 +0900)
> From: Tino Calancha <tino.calancha@gmail.com>
> Date: Thu, 22 Dec 2016 19:20:21 +0900
>
>
> 1)
> Save a file /tmp/test.el with contains:
>
> (defun mytest ()
> (dotimes (n 10)
> (message "[%d] Sleeping ..." n)
> (sleep-for 0.5))
> (message "End!")
> (sleep-for 1)
> (message nil))
>
> (defun run-test ()
> (dotimes (_ 50)
> (make-thread #'mytest))
> (message "Number of threads %d" (length (all-threads))))
>
> ;; (run-test)
>
> 2)
> emacs -Q -l /tmp/test.el
> ;; Evaluate (run-test) in buffer *scratch*; keep using Emacs, for instance,
> ;; split the window, and visit other buffers, or call (run-test) again:
> C-x 3
> C-x C-b
> C-o <down> RET
> ;; Sometimes Emacs crash or hangs.
Thanks.
It doesn't crash or hang here. Which is not surprising, since the
backtraces seem to indicate some issue with X11/xcb and threads. Ken,
could you take a look, please? Are we violating some X11 protocols by
calling redisplay from different threads?
> Following is the backtrace:
>
> (gdb) bt
When reporting backtraces with threads, please always show the
backtrace of all the threads in the process. Like this:
(gdb) thread apply all bt
> #12 0x000000000058f781 in terminate_due_to_signal (sig=6, backtrace_limit=2147483647) at emacs.c:379
> #13 0x00000000006278aa in die (msg=0x76d3a8 "((uintptr_t) start) % GC_POINTER_ALIGNMENT == 0", file=0x76cb30 "alloc.c", line=4893) at alloc.c:7315
> #14 0x0000000000622c81 in mark_memory (start=0x7fffbda63b17, end=0x7fffbda63b17) at alloc.c:4893
> #15 0x0000000000622cdb in mark_stack (bottom=0x7fffbda63b17 "", end=0x7fffbda63b17 "") at alloc.c:5058
> #16 0x00000000006e02f1 in mark_one_thread (thread=0x161bd60 <bss_sbrk_buffer+8396672>) at thread.c:558
Looks like the byte stack is unaligned. In run_thread I see this:
static void *
run_thread (void *state)
{
char stack_pos;
struct thread_state *self = state;
struct thread_state **iter;
self->m_stack_bottom = &stack_pos;
self->stack_top = &stack_pos;
which AFAIU could very well produce unaligned pointers. Does the
patch below prevent this crash?
> (gdb) bt
> #0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:58
> #1 0x00007fffefa9940a in __GI_abort () at abort.c:89
> #2 0x00007fffefa90e47 in __assert_fail_base (fmt=<optimized out>, assertion=assertion@entry=0x7ffff493fc00 "!xcb_xlib_threads_sequence_lost", file=file@entry=0x7ffff493fa6b "../../src/xcb_io.c", line=line@entry=259, function=function@entry=0x7ffff493fea8 "poll_for_event") at assert.c:92
> #3 0x00007fffefa90ef2 in __GI___assert_fail (assertion=0x7ffff493fc00 "!xcb_xlib_threads_sequence_lost", file=0x7ffff493fa6b "../../src/xcb_io.c", line=259, function=0x7ffff493fea8 "poll_for_event") at assert.c:101
> #4 0x00007ffff48cd77a in ?? () from /usr/lib/x86_64-linux-gnu/libX11.so.6
> #5 0x00007ffff48cd82b in ?? () from /usr/lib/x86_64-linux-gnu/libX11.so.6
> #6 0x00007ffff48cdb1d in _XEventsQueued () from /usr/lib/x86_64-linux-gnu/libX11.so.6
> #7 0x00007ffff48af58a in XFlush () from /usr/lib/x86_64-linux-gnu/libX11.so.6
> #8 0x0000000000541ff2 in x_flush (f=0x145ac30 <bss_sbrk_buffer+6557264>) at xterm.c:257
> #9 0x0000000000543111 in x_flip_and_flush (f=0x145ac30 <bss_sbrk_buffer+6557264>) at xterm.c:1217
> #10 0x000000000058e269 in flush_frame (f=0x145ac30 <bss_sbrk_buffer+6557264>) at frame.h:1481
> #11 0x0000000000467d3a in echo_area_display (update_frame_p=true) at xdisp.c:11435
> #12 0x0000000000464e43 in message3_nolog (m=...) at xdisp.c:10413
> #13 0x0000000000464af1 in message3 (m=...) at xdisp.c:10342
> #14 0x000000000063e868 in Fmessage (nargs=2, args=0x7fff3b015360) at editfns.c:3767
If you remove the calls to 'message' from the thread function, do
these problems go away?
> #2 0x00000000005bddd9 in emacs_abort () at sysdep.c:2364
> #3 0x00000000005a3903 in unblock_input_to (level=-1) at keyboard.c:7170
> #4 0x00000000005a391a in unblock_input () at keyboard.c:7186
Somehow more than one thread called block_input/unblock_input, sigh...
Here's the patch to try:
diff --git a/src/thread.c b/src/thread.c
index 6966df3..fcb7f69 100644
--- a/src/thread.c
+++ b/src/thread.c
@@ -644,12 +644,16 @@ do_nothing (Lisp_Object whatever)
static void *
run_thread (void *state)
{
- char stack_pos;
+ union
+ {
+ void *p;
+ char c;
+ } stack_pos;
struct thread_state *self = state;
struct thread_state **iter;
- self->m_stack_bottom = &stack_pos;
- self->stack_top = &stack_pos;
+ self->m_stack_bottom = (char *)&stack_pos;
+ self->stack_top = (char *)&stack_pos;
self->thread_id = sys_thread_self ();
acquire_global_lock (self);
next prev parent reply other threads:[~2016-12-22 17:28 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-22 10:20 bug#25247: 26.0.50; Concurrency crashes Tino Calancha
2016-12-22 17:28 ` Eli Zaretskii [this message]
2016-12-23 3:34 ` Tino Calancha
2016-12-23 8:34 ` Eli Zaretskii
2016-12-23 11:32 ` Tino Calancha
2016-12-23 14:14 ` Eli Zaretskii
2016-12-29 11:37 ` bug#25247: 26.0.50; Concurrency crashes with XLib Tino Calancha
2016-12-29 17:44 ` Eli Zaretskii
2016-12-30 3:13 ` Tino Calancha
2016-12-30 7:19 ` Ken Raeburn
2016-12-30 8:37 ` Eli Zaretskii
2016-12-30 9:41 ` Eli Zaretskii
2016-12-30 10:30 ` Elias Mårtenson
2016-12-30 11:05 ` Eli Zaretskii
2016-12-30 11:21 ` Elias Mårtenson
2016-12-30 18:54 ` Eli Zaretskii
2016-12-30 20:40 ` Eli Zaretskii
2016-12-31 11:05 ` Eli Zaretskii
2016-12-31 15:34 ` Elias Mårtenson
2016-12-31 15:51 ` Eli Zaretskii
2016-12-31 16:24 ` Elias Mårtenson
2016-12-31 17:18 ` Eli Zaretskii
2016-12-31 17:28 ` Elias Mårtenson
2016-12-31 18:06 ` Eli Zaretskii
2016-12-31 18:16 ` Elias Mårtenson
2016-12-31 18:29 ` Eli Zaretskii
2016-12-31 18:38 ` Eli Zaretskii
2016-12-30 13:45 ` Tino Calancha
2016-12-30 16:57 ` Eli Zaretskii
2017-01-06 0:03 ` npostavs
2017-01-06 7:48 ` Eli Zaretskii
2016-12-23 9:34 ` bug#25247: 26.0.50; Concurrency crashes Ken Raeburn
2016-12-23 10:04 ` 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=83a8bn27qn.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=25247@debbugs.gnu.org \
--cc=raeburn@raeburn.org \
--cc=tino.calancha@gmail.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.