[plt-scheme] Threading vs. System Threads

From: Robert Bruce Findler (robby at cs.uchicago.edu)
Date: Wed Feb 12 12:10:59 EST 2003

How do you handle killing of threads? That is, in the face of
custodian-shutdown-all or kill-thread, can messages appear multiple
times or can internal queues get put into bad states (deadlock)?


At Wed, 12 Feb 2003 12:07:52 -0500 (EST), Gregory Cooper wrote:
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> Actually, what I've been working on is a thread communication library for
> PLT Scheme.  My goal is to provide the essence of Erlang-style processes
> and message-passing, which involve the following three constructs:
> (spawn expr ...)
> creates a new thread to evaluate the given expressions, returning the
> thread's id, which can be used as a destination for messages;
> (! tid val)
> sends val to tid; this call returns (void) immediately, and the message is
> queued in tid's mailbox until tid is ready to process it;
> (receive [after timeout timeout-expr ...] ; (optional)
> 	 [pat expr ...]
> 	 ...)
> blocks the current thread until either the timeout (if given) expires or
> the thread receives a message matching one of the given patterns; the
> patterns can bind variables for use in the corresponding expressions,
> which are evaluated upon receipt of the message.
> I have an implementation of this interface that uses MzScheme's
> (preemptive) threads and performs quite well in general.  On my machine,
> for example, I can create several thousand threads in DrScheme without
> straining the system much.  However, in a restricted setting, I've found I
> can use a custom, cooperative threading model to improve performance
> significantly.  In particular, I can cut the spawning time by a factor of
> 25, reduce the resource requirements by a factor of 50, and also modestly
> reduce communication time (by up to a factor of 2).
> Greg

Posted on the users mailing list.