Date: Sun, 25 Feb 2007 03:11:40 -0500 From: "James Long" longster@gmail.com
I need the ability to create OS threads because of the blocking nature of the c calls (mainly with c functions that do network stuff).
One way to get around this is to serialize the communication between the Scheme OS thread and the other OS threads through a pipe, on which there can be non-blocking I/O. I implemented a proof of concept for Scheme48 at http:///mumble.net/~campbell/tmp/s48-addrinfo.tar.gz; perhaps you can scrounge some code or at least ideas from there.
On the Scheme side, Scheme threads call out to the C request code and enqueue a `placeholder' to be set when a response is returned; a placeholder is a write-once cell on which readers block until it is written to. The C request code sends a request by pipe (or any other mechanism, really, although we use a pipe here) to a different OS thread and returns a pointer to where the result will be stored. The Scheme threads then wait.
There is one dedicated Scheme thread that reads from a pipe, which the separate OS threads will write to in order to indicate a response; that Scheme thread distributes the responses to the appropriate Scheme threads that were waiting for them.