Subject: Re: bug#25247: 26.0.50; Concurrency crashes

From: Eli Zaretskii <[email-masked]>
Date: Fri, 23 Dec 2016 10:34:04 +0200

> From: Tino Calancha <[email-masked]>
> Cc: Tino Calancha <[email-masked]>, Ken Raeburn <[email-masked]>, [email-masked]
> Date: Fri, 23 Dec 2016 12:34:48 +0900
> 
> 
> Your patch solves one of the 2 problems:
> After your patch
> emacs -Q -l /tmp/test.el
> with unmarked
> (run-test)
> starts the session.

Thanks, pushed.

> > If you remove the calls to 'message' from the thread function, do
> > these problems go away?
> Unfortunately not.
> If i change test.el as follows:
> (that is, without `message' calls)
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> (defun mytest ()
>   (dotimes (n 10)
>     (sleep-for 0.5)))
> 
> (defun run-test ()
>   (dotimes (_ 50)
>     (make-thread #'mytest)))
> 
> ;; (run-test)
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> And then i start session:
> emacs -Q -l /tmp/test.el
> 
> After some simple keyboard inputs i get another crash
> with error:
> 
> X protocol error: BadWindow (invalid Window parameter) on protocol request 129
> When compiled with GTK, Emacs cannot recover from X disconnects.
> This is a GTK bug: https://bugzilla.gnome.org/show_bug.cgi?id=85715
> For details, see etc/PROBLEMS.
> Fatal error 6: Aborted
> 
> And backtraces:
> 
> (gdb) thread apply all bt

Please do:

  (gdb) thread apply all frame 1
  (gdb) thread apply all print context_acquired

The last command will print an error for a few threads, but that's
okay.  I hope it will still print the values for the 48 threads that
are waiting inside xg_select.  If not, I will have to ask you to do
that manually, like this:

  (gdb) thread 54
  (gdb) frame 1
  (gdb) p context_acquired
  (gdb) thread 53
  (gdb) frame 1
  (gdb) p context_acquired

etc., for all of the threads that show backtrace like this:

> Thread 54 (Thread 0x7fffbda64700 (LWP 5463)):
> #0  0x00007fffefb4638c in __pselect (nfds=14, readfds=0x7fffbda62c40, writefds=0x7fffbda62bc0, exceptfds=0x0, timeout=<optimized out>, sigmask=<optimized out>) at ../sysdeps/unix/sysv/linux/pselect.c:69
> #1  0x000000000070fe80 in xg_select (fds_lim=14, rfds=0x7fffbda63170, wfds=0x7fffbda630f0, efds=0x0, timeout=0x7fffbda630d0, sigmask=0x0) at xgselect.c:116
> #2  0x00000000006e031a in really_call_select (arg=0x7fffbda62e70) at thread.c:520

The number 54 in the "Thread 54" part of the header is the number you
give in the GDB "thread N" command above.

The expected result of all this is that only one thread has
context_acquired set to TRUE, the rest should have it FALSE.  If that
doesn't happen, we are somehow violating the Glib protocol of using
its context for reading events, and all kinds of problems could
happen.

> I get similar crashes after applying your patch.

That patch wasn't supposed to fix those, only the one with unaligned
pointers that caused an abort in GC.

Thanks.