[plt-scheme] Creating a suspended thread

From: Marc Feeley (feeley at iro.umontreal.ca)
Date: Tue Apr 14 00:31:09 EDT 2009

On 14-Apr-09, at 12:01 AM, Eli Barzilay wrote:

> On Apr 13, Marc Feeley wrote:
>>
>> The problem of conflating thread creation and activation is no
>> different than the problem of conflating function creation and
>> variable definition (which Scheme chose not to conflate).  You can
>> simulate anonymous functions with named functions by using a
>> temporary name.  But you pay a price in program clarity (elegance?)
>> and in run time cost (unless you have a Sufficiently Smart(tm)
>> compiler).
>
> Going down to more primitive forms doesn't always mean gaining clarity
> (or elegance) -- otherwise machine code would be much better than
> Scheme, and `call-with-current-continuation' would be much better than
> `let/cc'.  In other words, Scheme *did* choose to conflate a good
> number of features in its function form...
>
> More seriously, if the kind of problems that are solved by separating
> thread-creation from thread-activation can be solved with channels,
> then I choose the higher-level operation.  If it does turn out that
> there are some cases where the mzscheme facilities are insufficient,
> then my guess is that these cases are rare enough that paying the
> extra cost (if there is any) is perfectly fine with me -- in exactly
> the same way that I still prefer `lambda' as a better alternative to
> the low level features it conflates.


My position is that the lower level of a thread system should provide  
"make-thread" and "thread-start!".  The higher level procedure  
"thread" can be provided as a convenience to the user and be defined  
(by the runtime system) simply as:

(define (thread thunk)
   (thread-start! (make-thread thunk)))

That way the programmer can easily access the fundamental operations  
if he so wishes.  In other words

   thread = make-thread + thread-start!

It is analogous to saying

   "procedure definition" = lambda + "variable definition"

i.e.

(define (f x) (* x x)) = (define f (lambda (x) (* x x)))

The "lower level" features (lambda and define) are convenient to have  
even though a large part of many programs don't need them explicitly  
if procedures are defined using the special notation for procedure  
definition.

I'll shut up now!

Marc



Posted on the users mailing list.