[plt-scheme] scheme_check_threads gives Bus error on OS X

From: Jon Rafkind (workmin at ccs.neu.edu)
Date: Sun Nov 6 12:09:41 EST 2005

>The bus error results from MzScheme trying to call
>scheme_wakeup_on_input(), but your application doesn't set it. I'll
>change MzScheme to make setting scheme_wakeup_on_input optional, and
>you can avoid the problem meanwhile by setting scheme_wakeup_on_input
>to a function that does nothing.
>On the other hand, if you're not setting scheme_wakeup_on_input and
>instead relying on busy-waiting, you probably just want
>scheme_thread_block(0.0) to let other threads run.
Thanks for your reply. I tried setting scheme_wakeup_on_input to some 
dummy function and also I tried using scheme_thread_block(0.0) but both 
resulted in a Bus error. I put some debugging statements in 
mzscheme/src/thread.c and found that the variable p which should equal 
the scheme_current_thread was printing out as 0x0! Before my scheme 
application invokes the C code p prints out as 0x208aa8 but as soon as I 
call scheme_block_threads it becomes null. Just to be clear, I am not 
calling a C function that starts Cocoa's NSApplication I am just calling 
a C function that immediately calls scheme_thread_block and thats it. 
Are there any other places I should try to debug?

On a side note when I try to link with libmzscheme.a I get errors about 
the library being out of date and I should run ranlib on libmzscheme.a. 
After running ranlib on libmzscheme.a and libmzgc.a I can link with them ok.

>With either implementation, beware that calling the Cocoa API from
>other MzScheme threads probably won't work. MzScheme thread swapping is
>implemented by copying and overwriting the C stack. This means that if
>any other MzScheme thread calls into the Cocoa API, Cocoa may notice
>that the stack isn't consistent with the active event loop.
Hm, that is disheartening. I assume DrScheme uses the Aqua framework or 
something? Im not really familiar with OS X's gui stuff so I dont know 
the difference between Cocoa and Aqua but is Aqua the only framework 
that MzScheme can use?

Posted on the users mailing list.