[plt-scheme] Creating a suspended thread
On Apr 14, Marc Feeley wrote:
>
> 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!
But Matthew's code shows that `thread' with a channel (and
`thread-resume') can express `make-thread' and `thread-start!' -- so
if in both cases I get all operations (and if they perform roughly the
same), then I don't care either way. But if going with the above
equation means that `thread' is now noticeably slower, then I prefer
the other way since it makes the case I care about a priority. (I
have never had a need for a `thread/suspended'.)
> It is analogous to saying
>
> "procedure definition" = lambda + "variable definition"
And the other side of this analogy is:
lambda = goto + gosub
which Scheme did choose to conflate. This seems relevant to this
case: people who want the lowlevel `goto' feature will surely complain
about such an awkward way of getting it, and about possible higher
costs.
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://www.barzilay.org/ Maze is Life!