Subject: Re: bug#25172: 26.0.50; Concurrency feature, sit-for doesn't work (crashing and unexpected behaviour)

From: Eli Zaretskii <[email-masked]>
Date: Wed, 14 Dec 2016 18:03:11 +0200

> From: Elias Mårtenson <[email-masked]>
> Date: Wed, 14 Dec 2016 10:58:36 +0800
> Cc: Clément Pit--Claudel <[email-masked]>, 
> 	[email-masked]
> 
>  Can you try removing the calls to block_input/unblock_input from
>  xgselect.c, and see if these crashes then stop?
> 
> I have tried this now, and it's much more stable now. It doesn't immediately crash, and sometimes it doesn't
> crash at all.
> 
> When it crashes, it does so after several seconds, and I have captured two of these crashes.

Thanks.  Does the patch below help in any way with these crashes?

If not, it sounds like I'm out of my depth here.  The crashes you show
are deep in the bowels of Glib called by GTK; reading the (annoyingly
minimal) documentation of those APIs, I sense the danger of some basic
issue with calling these APIs from several threads.  If what the GTK
documentation tells everything there is to it, then the patch below
should fix these problems.  But if not, then I guess we will need help
from a GTK expert.

diff --git a/src/xgselect.c b/src/xgselect.c
index 2f23764..a9461a5 100644
--- a/src/xgselect.c
+++ b/src/xgselect.c
@@ -150,7 +150,7 @@ xg_select (int fds_lim, fd_set *rfds, fd_set *wfds, fd_set *efds,
 #else
   need_to_dispatch = true;
 #endif
-  if (need_to_dispatch)
+  if (need_to_dispatch && context_acquired)
     {
       int pselect_errno = errno;
       /* Prevent g_main_dispatch recursion, that would occur without