[plt-scheme] embedded MzScheme not started on main thread

From: Scott Walters (scott at integra-online.com)
Date: Mon Aug 26 19:27:18 EDT 2002

Thanks very much for your response.

I thought I'd take another stab at this and try 
your recommendation since we have a lot of 
existing MzScheme code that we'd like to reuse in 
a j2ee servlet environment.  We can't really 
upgrade to version 2 yet but I looked at the 
GC_stackbottom comment you made and had some 
questions.

I'm not really very knowledgeable about how the 
gc works but it seems like I would have to set 
the stack bottom for the MzScheme initializing 
thread to the address of a procedure variable 
inside a function that would not be returned from 
until the thread died.  Is this right?  If it is, 
I'm not sure how it can work in my setup since 
the Java servlet container controls the code that 
the thread initially executes so I don't really 
know where the stack bottom is by the time my 
Java code is invoked. Do you know of a way I can 
find out for Win32?

Also, does the gc store a stack bottom for all 
threads.  I assume it must but I guess this is 
handled by the MzScheme code. Does this affect 
what I have to do to set the stack bottom?

I tried a couple of things but they didn't seem 
to fix the problem.

First, I tried starting a C thread that sets 
GC_stackbottom to the address of a procedure 
variable, initializes scheme and then waits 
indefinitely. When this didn't work,  I tried 
setting the GC_USE_DLL compile flag on the gc 
since this is how it's ultimately ending up even 
though the dll I build is statically linking 
MzScheme.  Is this correct?

I also see where it's crashing now since I 
modified the make files to build a debug threaded 
version.  It bombs in the last line of the 
following function because the hhdr variable is 
null.  Does this suggest anything?

GC_bool GC_is_marked(p)
ptr_t p;
{
    register struct hblk *h = HBLKPTR(p);
    register hdr * hhdr = HDR(h);
    register int word_no = (word *)p - (word *)h;
    
    return(mark_bit_from_hdr(hhdr, word_no));
}

Thanks,
Scott Walters



8/1/2002 5:31:46 PM, Matthew Flatt 
<mflatt at cs.utah.edu> wrote:

>> I'm having a problem trying to embed 
>> MzScheme 103 into a Java application on 
>> Windows NT4-SP6.  It sees to work fine 
>> when I initialize MzScheme from the main 
>> app thread. If I initialize MzScheme from 
>> an alternate thread,  it crashes while 
>> executing Scheme code.  It doesn't always 
>> crash in the same place in the Scheme code 
>> which makes me think that the GC may be 
>> involved.  In both environments,  I 
>> statically link MzScheme into my 
>> application and set the 
>> GC_use_registered_statics flag since Java 
>> starts multiple threads.  Both 
>> environments also link with an MzScheme 
>> library and GC built with the WIN32
>> _THREADS define flag set.  
>
>I think you're right that it has something to do 
with GC, and with
>finding the stack base. You might try setting 
GC_stackbottom (I may
>have the variable name wrong) to an address that 
represents the base of
>the stack --- usually the address of a 
procedure-local variable.
>
>But if upgrading to v200 is possible, I 
recommend that first. Merely
>upgrading is unlikely to make the problem 
disappear, but the interface
>is cleaner for setting the stack base and 
registering globals, and I'm
>more confident that it works. In v200, call 
scheme_set_stack_base() to
>achieve the effect of setting GC_stackbottom and
>GC_use_registered_statics.
>
>Matthew
>
>








Posted on the users mailing list.