[plt-scheme] Boehm gc in embedded scheme application

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sat Aug 9 08:19:59 EDT 2003

At Thu, 07 Aug 2003 23:20:17 -0700, Stephen McCracken wrote:
> I'm considering embedding MzScheme into a C/C++ application.  The
> application has an interactive part, so I would need to use the incremental
> mode of the Boehm collector.  I'm concerned about bad interactions between
> MzScheme and the gc in the following circumstances:
> 
> * scheme calls C code, which uses gc_malloc
> * C code in a separate OS thread uses gc_malloc
> 
> Can anyone tell me if either is problematic?
> 
> I'm also interested to hear suggested best practices for using mzscheme in a
> C/C++ application that also uses the Boehm gc.

I started a message along the lines of "it should work if...", but I
now I'm forced to conclude that sharing the GC won't work well.

One main problem is that MzScheme uses a modified version of the Boehm
GC to get a different finalization semantics than the usual version.
We're hoping to eliminate this special finalization, but it will take
time. If this were the only problem, you might simple link your C++
code to MzScheme's version of the GC.

Another problem has to do with threads. MzScheme installs a pre-GC
callback that flushes various pointerful caches before the GC. If a
thread other than the MzScheme thread invokes the collector, then this
flushing could happen at a bad time as far as the MzScheme thread is
concerned.

Maybe you could just skip the pre-GC flushing when called in the wrong
thread, but the there's some post-GC work to fixup weak links in the
symbol table. I don't see an easy way around that one.

The only possibility I see is having *two* collectors, one for
MzScheme-allocated data and one for your application. Depending on your
platform and linker, this may be no problem, or it might be impossible.

Matthew



Posted on the users mailing list.