This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

dynamic-wind and call-with-new-thread


We are having some problems in understanding some of the rationale
behind the interaction between `dynamic-wind' and
`call-with-new-thread'.

`dynamic-wind' will call the outguard upon any non-local escape, and
apparently `call-with-new-thread' has been classified as such. That
is: if `call-with-new-thread' is called from within the body-thunk of
a `dynamic-wind', the outguard (and subsequently the inguard) will be
activated.

But why is this so? From the point of view of the initiating thread
(the one that calls `call-with-new-thread'), call/nt does not appear
as a non-local escape, IMHO. Unless active measures (such as locking)
prevents it, the initiating thread should be ready to go rather
shortly after the new thread has been created. Call/cc on the other
hand is more obviously a non-local escape, since the initiating
continuation never will run again, unless explicitly activated by the
new continuation.

One consequence of the current situation is that `with-mutex' cannot
(at least not conveniently) be used to control thread creation in a
multithreaded application.

As an example: the idea to use a mutex which is locked by a master
thread and only released when all child threads has been created will
not work with the current `with-mutex' and call/nt, since each call of
call/nt will make the master thread lose the mutex.

This is not to say that the current setup is bad or malfunctining, but
we just cannot think of any examples where it is usefull (and we were
bitten by our lacking understanding of the `with-mutex'
behaviour).

Can anybody shine some light on the matter?

---------------------------+--------------------------------------------------
Christian Lynbech          | Telebit Communications A/S                       
Fax:   +45 8628 8186       | Fabrik 11, DK-8260 Viby J
Phone: +45 8628 8177 + 28  | email: chl@tbit.dk --- URL: http://www.telebit.dk
---------------------------+--------------------------------------------------
Hit the philistines three times over the head with the Elisp reference manual.
                                        - petonic@hal.com (Michael A. Petonic)