[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multithreading?



Quoting ender:
> I'm using mzscheme embedded in a fairly complex c++ application that
> is itself multithreaded. That is, the c++ app handles its own
> threading. What kinds of issues arise in embedding mzscheme in this
> environment?

Compiled in the normal way, MzScheme cannot be called from multiple
threads at once. But if a multi-threaded C++ app calls MzScheme
functions from only one thread at a time, and only that thread's stack
points to GCable objects, then everything's fine (modulo a Windows GC
problem described below).

For a few OSes, MzScheme can also be compiled to use OS-defined threads
for Scheme threads, and in that case it can be called from multiple
threads at once --- but only if MzScheme itself created the threads via
scheme_thread(). Because of the scheme_thread() restriction, it's not a
solution for all applications.


The Windows GC problem: even if MzScheme functions are only used in a
single OS thread, the conservative garbage collector can get tripped up
by threads under Windows. The collector finds static variables by
scanning all mapped memory pages. If one thread unmaps a page while
another one is running the collector, the collector can segfault. To
solve this problem, the collector needs to be compiled for multiple
threads and as a DLL. Then, the collector can see all threads ever
created, and it can stop them while collecting.

Matthew