[plt-scheme] capturing output from different threads

From: Dave Griffiths (dave at pawfal.org)
Date: Wed Mar 5 09:17:43 EST 2008

> Dave Griffiths wrote:
>> Hi all,
>> I've been capturing the output from an embedded interpreter like so:
>> outport = scheme_make_byte_string_output_port();
>> errport = scheme_make_byte_string_output_port();
>> scheme_set_param(scheme_current_config(), MZCONFIG_OUTPUT_PORT,
>> outport);
>> scheme_set_param(scheme_current_config(), MZCONFIG_ERROR_PORT, errport);
>> ...
>> scheme_eval_string_all(...)
>> ...
>> outmsg=scheme_get_sized_byte_string_output(outport,&size);
>> errmsg=scheme_get_sized_byte_string_output(errport,&size);
>> But this seems to crash the garbage collector elsewhere when I spawn a
>> plt
>> thread in my script. Reading the docs it seems that scheme_set_param
>> only
>> works for one thread, so I can imagine it would only work for the main
>> thread, so 1) is there a way to get new threads to inherit the main
>> thread's parameters and 2) will it also make the garbage collector
>> happy?
>> ;)
> As the doc says, scheme_set_param only works for the current thread. For
> your embedded Scheme program, I assume for all C code, the current
> thread means the main Scheme thread, right?
> For your question1: All newly-created thread inherits the parameter
> settings of the creating thread.

Ah, ok - good to know. I still need to find out the cause of the crashes
though. My code has been stable with a single thread for a long time, and
if I remove the logging it's stable with multiple threads.

But such is garbage collection :) I'll try to distill a test app which
exhibits this behaviour, hopefully in the course of doing that I'll find
the problem in my code.

>> Also maybe related, I find that calling scheme_eval_string_all on the
>> interpreter causes all threads to get run, calling scheme_check_threads
>> doesnt seem to make any difference.
> I didn't get what you mean here. But that's looks like the correct
> behaver.

Ah, I initially thought you needed to call scheme_check_threads to get
non-main thread to run at all - on reading the docs again I see it's to
wait for all threads to finish. I was confused.



Posted on the users mailing list.