<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Matthew Flatt wrote:
<blockquote cite="mid200504271643.j3RGhj2c048058@slow.flux.utah.edu"
type="cite">
<pre wrap=""> For list-related administrative tasks:
<a class="moz-txt-link-freetext" href="http://list.cs.brown.edu/mailman/listinfo/plt-scheme">http://list.cs.brown.edu/mailman/listinfo/plt-scheme</a>
At Tue, 26 Apr 2005 07:45:51 -0700, Barry Tolnas wrote:
</pre>
<blockquote type="cite">
<pre wrap="">[...] When I tried writing a
simple test shown below to put scheme in its own SDL thread (which is a
pthread underneath) scheme_basic_env() crashes. A stack trace is shown
after the code listing. It seems there is an infinite recursion in calls
to GC_clear_stack_inner. [...]
int DoScheme(void *args)
{
Scheme_Env* e;
printf("Scheme thread starting\n");
scheme_set_stack_base(NULL, 1); /* required for OS X, only */
</pre>
</blockquote>
<pre wrap=""><!---->
My guess is that the GC can't find the stack base, and so you'll have
to help it by supplying a non-NULL pointer for the first argument of
scheme_set_stack_base, something like this:
int DoScheme(void *args) {
int dummy;
scheme_set_stack_base(&dummy, 1);
return Really_DoScheme(args);
}
int Really_DoScheme(void *args)
{
Scheme_Env* e;
printf("Scheme thread starting\n");
e = scheme_basic_env();
scheme_eval_string("(display \"hello world\n\")", e);
fprintf(stdout,"Scheme Thread finished\n");
fflush(stdout);
return 0;
}
I'm guessing because I'm never sure how well Boehm's conservative GC
can actually find the stack and static variables. With PLT-implemented
GCs, we always punt and require the program to supply that information,
like above.
Matthew
</pre>
</blockquote>
Thanks, Matthew, thats just what I needed. After some experimenting I
realized that the extra function was not needed (maybe I'll see why its
needed when the program gets more complicated.) Below is a working
version that simply uses the Scheme_Env* variable to locate the stack
base.<br>
<br>
Barry<br>
<br>
<tt>#include "scheme.h"<br>
#include "SDL.h"<br>
#include "SDL_thread.h"<br>
<br>
int DoScheme(void* args)<br>
{<br>
Scheme_Env* e;<br>
<br>
printf("Scheme thread starting\n");<br>
<br>
scheme_set_stack_base(&e, 1); /* required for OS X, only */ <br>
e = scheme_basic_env();<br>
scheme_eval_string("(display \"hello world\n\")", e);<br>
<br>
printf("Scheme Thread finished\n");<br>
fflush(stdout);<br>
return 0;<br>
}<br>
<br>
int main(int argc, char *argv[]) <br>
{<br>
SDL_Thread* thread;<br>
<br>
thread = SDL_CreateThread(DoScheme,NULL);<br>
while(1) { };<br>
return 0;<br>
}<br>
</tt><br>
</body>
</html>