unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: ludo@gnu.org (Ludovic Courtès)
Cc: guile-user@gnu.org
Subject: Re: guile 2.0.9 build on mingw
Date: Wed, 12 Jun 2013 20:46:07 +0300	[thread overview]
Message-ID: <83a9mvkysg.fsf@gnu.org> (raw)
In-Reply-To: <87txl4mh5p.fsf@gnu.org>

> From: ludo@gnu.org (Ludovic Courtès)
> Cc: Mark H Weaver <mhw@netris.org>,  guile-user@gnu.org
> Date: Wed, 12 Jun 2013 00:11:46 +0200
> 
> > What eventually did the trick was configuring --with-threads=no.  Once
> > I did that, the build ran successfully and almost 100% cleanly to
> > completion.  (I will report the details about "almost" later.)
> >
> > I will try to compare the two builds and find what breaks the one with
> > threads.  Since my knowledge about pthreads in general and on Windows
> > in particular is strictly zero, I'm not sure I'll know where to look.
> > So perhaps the following observation will help someone here to come up
> > with ideas or hints about where to look: Guile gets stuck when it is
> > about to exit.  That is, it processes its input completely (e.g.,
> > compiles the .scm file), writes out the corresponding output (e.g.,
> > the .go file), announces that the output was written, and then gets
> > stuck.  So this suggests something related to some bookkeeping done at
> > exit; any ideas what that could be?
> 
> The backtrace you reported before suggests that it’s stuck waiting for a
> signal delivery thread mutex, right?  I have no idea how this would
> happen, though.

I looked deeper into this.  What I saw surprised me, but maybe that's
because I know nothing about pthreads, nor how Guile uses them.  I
will describe my findings in the hope that someone here will know
more.  In a nutshell, I think the hang waiting for a mutex is a
symptom, not the problem; see below.

What I did was stop Guile at the entry to 'main', and then attach GDB
and set a breakpoint at scm_i_ensure_signal_delivery_thread, before
letting Guile proceed.  I expected that function to be called some
time during the startup, and I expected to see GDB announce a new
thread.  Surprisingly, none of that happened.  Instead, the function
is called when Guile is done (it was compiling a .scm file), and is
exiting!  See the backtrace below; you can clearly see that the
top-level call-stack frame is in ExitProcess, and the whole sequence
of calls leading to the attempt to create a signal delivery thread
starts in on_thread_exit.

What happens next is that the attempt to launch that thread fails
here:

     SCM
     scm_spawn_thread (scm_t_catch_body body, void *body_data,
		       scm_t_catch_handler handler, void *handler_data)
     {
       spawn_data data;
       scm_i_pthread_t id;
       int err;

       data.parent = scm_current_dynamic_state ();
       data.body = body;
       data.body_data = body_data;
       data.handler = handler;
       data.handler_data = handler_data;
       data.thread = SCM_BOOL_F;
       scm_i_pthread_mutex_init (&data.mutex, NULL);
       scm_i_pthread_cond_init (&data.cond, NULL);

       scm_i_scm_pthread_mutex_lock (&data.mutex);
       err = scm_i_pthread_create (&id, NULL, spawn_thread, &data); <<<<<<<
       if (err)
	 {
	   scm_i_pthread_mutex_unlock (&data.mutex);
	   errno = err;
	   scm_syserror (NULL);
	 }

scm_i_pthread_create returns err = 11 (EAGAIN), and then Guile calls
scm_syserror.  I believe that call outputs the Scheme backtrace, and
then Guile hangs as I described.

The call to start the signal delivery thread comes from here:

     /* Perform thread tear-down, in guile mode.
      */
     static void *
     do_thread_exit (void *v)
     {
       scm_i_thread *t = (scm_i_thread *) v;

       /* Ensure the signal handling thread has been launched, because we might be
	  shutting it down.  This needs to be done in Guile mode.  */
       scm_i_ensure_signal_delivery_thread ();  <<<<<<<<<<<<<<<<<<<<<

Why isn't the signal delivery thread launched at program start, and
why is it launched at exit?

Also, is it possible for you or someone else to describe how the
signal delivery stuff is supposed to work, especially since there are
some MinGW related comments in scmsigs.c that mention signals between
processes (how's that related? Guile is a single process, right?)?
I'd like to understand a bit more what is going on here.

> > Another set of disabled features is the network related functions --
> > for some reason, the build process insists on h_errno being available,
> > although h_errno is an obsolete facility that AFAIK no one is treating
> > seriously anymore.  Why not use errno instead?
> 
> I don’t know.  It’s used only in net_db.c, and only if ‘h_errno’ is
> available.
> 
> Is there any harm in using it when it’s available?

No, of course not.  The harm is to disable all network features when
h_errno is _not_ available.

> Could it be that older-but-not-too-old MinGW versions required use of
> ‘h_errno’?

I sincerely doubt that.  Windows doesn't have h_errno, and AFAIK never
had.

Here's the backtrace when scm_spawn_thread is called during exit:

     Breakpoint 1, scm_spawn_thread (
	 body=body@entry=0x436350 <signal_delivery_thread>,
	 body_data=body_data@entry=0x0, handler=0x4317a4 <scm_handle_by_message>,
	 handler_data=handler_data@entry=0x4e5a60 <scm_i_open_file__name_string_stringbuf+20>) at threads.c:1119
     1119    {
     (gdb) bt
     #0  scm_spawn_thread (body=body@entry=0x436350 <signal_delivery_thread>,
	 body_data=body_data@entry=0x0, handler=0x4317a4 <scm_handle_by_message>,
	 handler_data=handler_data@entry=0x4e5a60 <scm_i_open_file__name_string_stringbuf+20>) at threads.c:1119
     #1  0x00436328 in start_signal_delivery_thread () at scmsigs.c:200
     #2  0x6248b751 in pthread_once () from d:\usr\bin\pthreadGC2.dll
     #3  0x0043642c in scm_i_ensure_signal_delivery_thread () at scmsigs.c:212
     #4  0x00432c10 in do_thread_exit (v=0x9b0f00) at threads.c:671
     #5  0x0045f8bc in c_body (d=0x28f6a0) at continuations.c:511
     #6  0x00454b9b in vm_regular_engine (vm=0xb95c80, program=0x0,
	 argv=0x23f00a4, nargs=5121210) at vm-i-system.c:855
     #7  0x00414608 in scm_call_4 (proc=0x926b28, arg1=arg1@entry=0x404,
	 arg2=arg2@entry=0x5408d80, arg3=arg3@entry=0x5408d70,
	 arg4=arg4@entry=0x5408d60) at eval.c:507
     #8  0x004312b2 in scm_catch_with_pre_unwind_handler (key=0x404,
	 thunk=0x5408d80, handler=0x5408d70, pre_unwind_handler=0x5408d60)
	 at throw.c:86
     #9  0x0043144e in scm_c_catch (tag=tag@entry=0x404, body=0x5408d80,
	 body@entry=0x45f8ac <c_body>, body_data=0x5408d70,
	 body_data@entry=0x28f6a0, handler=0x5408d60,
	 handler@entry=0x45fb60 <c_handler>,
	 handler_data=handler_data@entry=0x28f6a0,
	 pre_unwind_handler=pre_unwind_handler@entry=0x45f9cc <pre_unwind_handler>, pre_unwind_handler_data=pre_unwind_handler_data@entry=0xb95c40) at throw.c:213
     #10 0x0045ff4b in scm_i_with_continuation_barrier (
	 body=body@entry=0x45f8ac <c_body>, body_data=body_data@entry=0x28f6a0,
	 handler=handler@entry=0x45fb60 <c_handler>,
	 handler_data=handler_data@entry=0x28f6a0,
	 pre_unwind_handler=pre_unwind_handler@entry=0x45f9cc <pre_unwind_handler>, pre_unwind_handler_data=0xb95c40) at continuations.c:449
     #11 0x0045ffdc in scm_c_with_continuation_barrier (
	 func=0x432c00 <do_thread_exit>, data=0x9b0f00) at continuations.c:545
     #12 0x00431e04 in with_guile_trampoline (data=0x28f790) at threads.c:890
     #13 0x709cffa0 in ?? () from d:\usr\bin\libgc-1.dll
     #14 0x004326ec in with_gc_active (data=0x28f790,
	 func=0x431dec <with_guile_trampoline>) at threads.c:238
     #15 with_guile_and_parent (base=0x28f768, data=0x28f790) at threads.c:936
     #16 0x709cae6f in ?? () from d:\usr\bin\libgc-1.dll
     #17 0x004328f0 in scm_i_with_guile_and_parent (parent=<optimized out>,
	 data=0x9b0f00, func=0x432c00 <do_thread_exit>) at threads.c:951
     #18 scm_with_guile (func=0x432c00 <do_thread_exit>, data=0x9b0f00)
	 at threads.c:957
     #19 0x709cae6f in ?? () from d:\usr\bin\libgc-1.dll
     #20 0x00431e76 in on_thread_exit (v=0x9b0f00) at threads.c:754
     #21 0x62481f14 in ptw32_callUserDestroyRoutines ()
	from d:\usr\bin\pthreadGC2.dll
     #22 0x624855a1 in pthread_win32_thread_detach_np ()
	from d:\usr\bin\pthreadGC2.dll
     #23 0x62485a45 in DllMain@12 () from d:\usr\bin\pthreadGC2.dll
     #24 0x624810ed in DllMainCRTStartup@12 () from d:\usr\bin\pthreadGC2.dll
     #25 0x77c69950 in ntdll!RtlQueryEnvironmentVariable ()
	from C:\Windows\SysWOW64\ntdll.dll
     #26 0x62480000 in ?? ()
     #27 0x77c7d6b2 in ntdll!LdrShutdownProcess ()
	from C:\Windows\SysWOW64\ntdll.dll
     #28 0x624810c0 in __dll_exit () from d:\usr\bin\pthreadGC2.dll
     #29 0x77c7d554 in ntdll!RtlExitUserProcess ()
	from C:\Windows\SysWOW64\ntdll.dll
     #30 0x75e97a0d in KERNEL32!ExitProcess ()
	from C:\Windows\syswow64\kernel32.dll




  reply	other threads:[~2013-06-12 17:46 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-20 19:46 guile 2.0.9 build on mingw Panicz Maciej Godek
2013-05-20 20:05 ` Eli Zaretskii
2013-05-20 20:46   ` Andy Wingo
2013-05-20 21:09     ` objc
2013-05-21  2:43       ` Eli Zaretskii
2013-05-22 15:26     ` Eli Zaretskii
2013-06-07  8:37       ` Eli Zaretskii
2013-06-07 12:44       ` Ludovic Courtès
2013-06-07 14:59         ` Eli Zaretskii
2013-06-09 17:10           ` Eli Zaretskii
2013-06-09 20:33             ` Ludovic Courtès
2013-06-09 21:16               ` Andy Wingo
2013-06-09 21:35                 ` Ludovic Courtès
2013-06-10 16:18                   ` Eli Zaretskii
2013-06-10 16:18                 ` Eli Zaretskii
2013-06-10 16:23               ` Eli Zaretskii
2013-06-10 19:09                 ` Mark H Weaver
2013-06-10 19:49                   ` Eli Zaretskii
2013-06-10 20:54                     ` Mark H Weaver
2013-06-11 16:53                       ` Eli Zaretskii
2013-06-11 22:11                         ` Ludovic Courtès
2013-06-12 17:46                           ` Eli Zaretskii [this message]
2013-06-18 21:51                             ` Why launch the Guile signal delivery thread on exit? (was Re: guile 2.0.9 build on mingw) Mark H Weaver
2013-06-19 15:51                               ` Eli Zaretskii
2013-06-19 16:06                               ` Julian Graham
2013-06-19 19:20                               ` Ludovic Courtès
2013-06-12 17:57                         ` guile 2.0.9 build on mingw Eli Zaretskii
2013-06-13 13:26                           ` Eli Zaretskii
2013-06-16 14:19                             ` Ludovic Courtès
2013-06-13 13:33                           ` Eli Zaretskii
2013-06-16 14:36                             ` Ludovic Courtès
2013-06-16 15:40                               ` Eli Zaretskii
2013-06-16 14:55                             ` Ludovic Courtès
2013-06-16 15:47                               ` Eli Zaretskii
2013-06-16 18:59                                 ` Ludovic Courtès
2013-06-13 13:40                           ` Eli Zaretskii
2013-06-16 14:59                             ` Ludovic Courtès
2013-06-17 15:41                               ` Eli Zaretskii
2013-06-18 20:45                                 ` Ludovic Courtès
2013-06-18 22:28                                   ` Mark H Weaver
2013-06-19  3:03                                     ` Eli Zaretskii
2013-06-19 19:26                                     ` Ludovic Courtès
2013-06-19 20:02                                       ` Eli Zaretskii
2013-06-19  2:59                                   ` Eli Zaretskii
2013-06-19 15:56                                   ` Eli Zaretskii
2013-06-19 19:38                                     ` Ludovic Courtès
2013-06-13 13:41                           ` Eli Zaretskii
2013-06-16 15:04                             ` Ludovic Courtès
2013-06-16 15:48                               ` Eli Zaretskii
2013-06-16 14:44                           ` Ludovic Courtès
2013-06-16 15:41                             ` Eli Zaretskii
2013-06-12 17:59                         ` Eli Zaretskii
2013-06-16 14:46                           ` Ludovic Courtès
2013-06-12 18:02                         ` Eli Zaretskii
2013-06-16 19:50                           ` Ludovic Courtès
2013-06-16 20:22                             ` Eli Zaretskii
2013-06-17 15:45                           ` Mark H Weaver
2013-06-18 17:17                             ` Eli Zaretskii
2013-06-18 19:31                               ` Eli Zaretskii
2013-06-18 20:19                                 ` Ludovic Courtès
2013-06-19  2:53                                   ` Eli Zaretskii
2013-06-19 19:28                                     ` Ludovic Courtès
2013-06-19 19:56                                       ` Eli Zaretskii
2013-05-26 20:41     ` Panicz Maciej Godek

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

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83a9mvkysg.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=guile-user@gnu.org \
    --cc=ludo@gnu.org \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).