On Wed, Mar 25, 2009 at 9:45 AM, Wacek Kusnierczyk <
[email protected]> wrote:
>
> indeed, you protect the stream, but you do not protect P. the issue
> with the two latter above is that P is bound (to a port) in a thread
> different from that in which it is declared. since you have no
> guarantees on when a thread is run, this solution has a hole: P can be
> bound in another thread (e.g., the parent one) to whatever value,
> causing an error when the child thread attempts to execute its NewPort.
> this may not be a serious risk in some cases, but if, for example, you
> want to distribute P and thus have no control over what is being done to
> it there, there may be ugly surprises.
>
> one quick solution to this would be to declare and bind P as well as
> create the thread in one pass, so to speak:
>
> declare
> P = local P in
> thread
> for Msg in {NewPort $ P} do
> {Browse Msg} end end
> P end
>
> the parent thread can only proceed while the newly declared P is bound
> to the port created inside the local statement, and P cannot be bound to
> whatever else in any other thread.
But your proposal does not "protect" the variable P either... The
local...end statement should either wait on P before returning it, or return
a read-only view of the variable. The following is safe:
declare
P = local P1 in
thread
for Msg in {NewPort $ P1} do {Browse Msg} end
end
!!P1
end
Cheers,
raph
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users