[racket-dev] Using places to synchronize with C threads?

From: Kevin Tew (tewk at cs.utah.edu)
Date: Tue Sep 20 23:47:00 EDT 2011

Place channels only work between places (os threads spawned using the 
`place' primitives).
Place channels can't be used with an OS thread spawned by an arbitrary C 


src/racket/src/mzrt.c contains synchronization operations for use 
between OS threads.
Place channels are built on top of the low level wrappers found in 
The wrappers in src/racket/src/mzrt.c can safely be called from any C 
The downside is that these OS thread synchronization are not exposed in 
the racket language.
The wrappers aren't documented, but they are just a platform portability 
layer over pthread synchronization primitives.

If you are spawning the OS thread, you might want to look at Ryan's 
sqlite db layer which places the sqlite ffi calls in a second `place' so 
the interactivity of the main `place' is preserved.
If the OS thread is spawned by a third party library, you might be able 
to use the ffi and the non-blocking mzrt_mutex_trylock call to build 
what you need.

If none of the above work, we might need to build some more 
infrastructure for synchronizing with OS threads.


On 09/20/2011 12:17 PM, John Clements wrote:
> It looks like you've done the heavy lifting of creating primitives that can be used to synchronize between OS threads.  Is there any way to use place channels to interact between the main Racket thread and an OS thread spawned by an audio library?  I don't see any documentation that provides a C interface to the place primitives, and I've learned the hard way that I can't assume that calling racket functions in a C thread is safe.
> John

Posted on the dev mailing list.