[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Comments on SRFI-39



Olin wrote:

  Spawning a thread, calling a function -- it's a dynamic nesting. 

The whole point to spawning a thread is that it isn't a dynamic
nesting.  If you wanted dynamic nesting you wouldn't spawn a thread,
you would just call the thunk.  The new thread's execution may happen
before the spawning call returns or it may happen after the spawning
thread has finished or the two may be interleaved.  Where's the
nesting?

If threads inherit dynamic bindings but DYNAMIC-WIND thunks are not
called when switching between threads (as they aren't in SRFI 18),
you get two different notions of dynamic nesting.  Consider the
following:
  
  (let ((param (make-parameter (lambda () 'initial)))
        (x 'out))
    (parameterize ((param (lambda () x)))
      (dynamic-wind (lambda () (set! x 'in))
                    (spawn (lambda ()
                             (display ((param)))))
                    (lambda () (set! x 'out)))))

If you use SRFI 18 and SRFI 39 then spawning a thread is a dynamic
nesting but running one is not and this prints IN or OUT.  This makes
no sense to me.  Why does the new thread see the PARAMETERIZE but not
the DYNAMIC-WIND?

If you want spawning a thread to be a dynamic nesting then you should
make running one also be dynamic.  This gives you parameter inheritance,
you run the DYNAMIC-WIND thunks on thead switches , and the code above
prints IN.  If threads do not have any dynamic nesting then you don't
have parameter inheritance, don't run the thunks, and it prints INITIAL.
Both of these make sense, but the second one seems more useful.

                                          -Richard