guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: threading issue in 1.8.3


From: Neil Jerram
Subject: Re: threading issue in 1.8.3
Date: Wed, 30 Jan 2008 23:41:48 +0000
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux)

Neil Jerram <address@hidden> writes:

> Antoine Mathys <address@hidden> writes:
>
>> Hello,
>>
>> I am having a problem with threads in 1.8.3 .
>
>> It seems that for some reason you cannot load modules from a different thread
>> than the one which first initialized guile.
>>
>> Any idea how to get this to work ?
>
> Apologies for the delay in responding...
>
> I think this is caused by the second thread not knowing what its
> current module is.  Can you try adding, before the scm_shell() call:
>
>   scm_set_current_module (scm_lookup_closure_module (SCM_BOOL_F));
>
> and report if that helps?

This problem was a bit more complex than it looked.

scm_shell () with no command line args expands to

  (begin (turn-on-debugging) (load-user-init) (top-repl))

And (top-repl) calls (set-current-module guile-user-module) very early
on, which means that any `use-modules' calls after that will be fine.

Therefore, the reported call stack (which indicates a problem in a
`use-modules' call, because of (current-module) being #f) can only be
caused by a `use-modules' call during the (load-user-init) - i.e. when
loading ~/.guile.

(To confirm this: my ~/.guile had a `use-syntax' call in it (which is
mostly equivalent to `use-modules'), and I got the same stack as you;
when I commented that out, I didn't see the reported stack any more.)

Anyway, code in ~/.guile should expect (current-module) to be sane, so
the necessary fix is still to make sure that (current-module) always
returns a module (so long as the module system has booted).  My
proposed patch for this is attached.

Two other notes for the record.

1. In my tests, the test program hung after the second thread had
   begun (top-repl), before trying to read any input from stdin.  This
   was because the second thread decided to GC, and so tried to put
   the first thread to sleep.  Put the first thread was blocked inside
   pthread_join ().  The fix for this is for the test program to do
   the pthread_join () inside a scm_without_guile () call, as in the
   attached patch.

2. If the second thread had been started in Scheme, it would have
   inherited the first thread's value of (current-module), which was
   already non-#f (as a result of the (define-module ...) call at the
   end of boot-9.sc,).  So this problem only occurs with multiple
   threads started in C using scm_with_guile ().

Regards,
        Neil

Attachment: test-with-guile.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]