* Unable to make threads from scm_c_primitive_load'ed files/Previously scm_c_define_gsubr-defined values unbound in new threads
@ 2008-03-08 16:53 Remco Bras
2008-03-08 21:39 ` Neil Jerram
0 siblings, 1 reply; 2+ messages in thread
From: Remco Bras @ 2008-03-08 16:53 UTC (permalink / raw)
To: bug-guile
[-- Attachment #1: Type: text/plain, Size: 1278 bytes --]
Hello,
I have run into a double problem with guile, that has to do with threads. The
situation is roughly as follows. First, scm_init_guile is called from one
thread, after which scm_c_define_gsubr is used in that thread and
scm_c_primitive_load is called to load several files. The first problem I
have encountered is that make-thread is unbound when evaluating the code in
the files I load, making it impossible to make threads this way. Other ways
to spawn threads fail as well. For example, (call-with-new-thread (lambda ()
(load "keys.scm"))) fails with a SIGSEGV. The attachment backtrace.txt
contains a backtrace of this particular failure.
Since I had to be able to load files in new threads rather than the current, I
tried doing so with a C function, exposed to Scheme with scm_c_define_gsubr.
The function, in case that is important, is included in the attached file
guile.c. Doing things this way succeeds in creating threads, but once it
attempts to evaluate any code in the file, it fails because the procedures I
previously defined with scm_c_define_gsubr() are unbound.
Is there any way to do either (make-thread load filename) or something
equivalent in scripts loaded with scm_c_primitive_load?
Thanks in advance for your time,
Remco Bras.
[-- Attachment #2: backtrace.txt --]
[-- Type: text/plain, Size: 656 bytes --]
Backtrace:
In unknown file:
?: 0* [#<procedure #f ()>]
In test.scm:
41: 1* [load-module "mob_event_test.scm"]
In unknown file:
?: 2 [save-module-excursion #<procedure #f ()>]
...
?: 3 [dynamic-wind #<procedure #f ()> #<procedure #f ()> #<procedure #f ()>]
?: 4* [#<procedure #f ()>]
?: 5* (let* ((oldname #)) (apply basic-load (if # # filename) reader))
?: 6* (and (current-load-port) (port-filename (current-load-port)))
?: 7 [port-filename {#<closed: file 0>}]
<unnamed port>: In procedure port-filename in expression (port-filename (current-load-port)):
<unnamed port>: Wrong type argument in position 1: #<closed: file 0>
[-- Attachment #3: guile.c --]
[-- Type: text/x-csrc, Size: 272 bytes --]
int
load_in_thread_callback(void* filename)
{
scm_init_guile();
scm_c_primitive_load(filename);
return EXIT_SUCCESS;
}
SCM
guile_load_in_thread(SCM filename)
{
SDL_CreateThread(load_in_thread_callback,scm_to_locale_string(filename));
return SCM_UNSPECIFIED;
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Unable to make threads from scm_c_primitive_load'ed files/Previously scm_c_define_gsubr-defined values unbound in new threads
2008-03-08 16:53 Unable to make threads from scm_c_primitive_load'ed files/Previously scm_c_define_gsubr-defined values unbound in new threads Remco Bras
@ 2008-03-08 21:39 ` Neil Jerram
0 siblings, 0 replies; 2+ messages in thread
From: Neil Jerram @ 2008-03-08 21:39 UTC (permalink / raw)
To: Remco Bras; +Cc: bug-guile
Hi Remco,
Thanks for your email...
Remco Bras <vrsoft@gmail.com> writes:
> Hello,
>
> I have run into a double problem with guile, that has to do with threads. The
> situation is roughly as follows. First, scm_init_guile is called from one
> thread, after which scm_c_define_gsubr is used in that thread and
> scm_c_primitive_load is called to load several files. The first problem I
> have encountered is that make-thread is unbound when evaluating the code in
> the files I load, making it impossible to make threads this way.
That might be resolved by adding (use-modules (ice-9 threads)) to the
start of the code that calls make-thread. Can you try that?
> Other ways
> to spawn threads fail as well. For example, (call-with-new-thread (lambda ()
> (load "keys.scm"))) fails with a SIGSEGV. The attachment backtrace.txt
> contains a backtrace of this particular failure.
Note that the backtrace is describing a Scheme-level error, not a
SIGSEGV. Are you saying that there was a SIGSEGV as well?
Anyway, the backtrace implies, I think, that the current-load-port had
previously been set to stdin, and that stdin has been closed. Would
that make sense in your program?
> Since I had to be able to load files in new threads rather than the current, I
> tried doing so with a C function, exposed to Scheme with scm_c_define_gsubr.
> The function, in case that is important, is included in the attached file
> guile.c. Doing things this way succeeds in creating threads, but once it
> attempts to evaluate any code in the file, it fails because the procedures I
> previously defined with scm_c_define_gsubr() are unbound.
Are you able to post (a link to) your complete program? I'm not sure
I'm understanding everything from your description here.
Regards,
Neil
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-03-08 21:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-08 16:53 Unable to make threads from scm_c_primitive_load'ed files/Previously scm_c_define_gsubr-defined values unbound in new threads Remco Bras
2008-03-08 21:39 ` Neil Jerram
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).