I was not checking my Mozart folder for a few days and good to see that
discussion went forward. Indeed, the way I was declaring Port as global
variable did turn out to be an untenable solution, since the stream was
keeping data for all the runs until the server got restarted. Not only
the port/stream was garbage collected I had to parse all the old data at
each run to get into the information pertaining to the present run. Thus
I came up with the solution in declaring the Port at local level and
then passing it around through functions wherever it needed. This way
the port gets reinitialized at each run and hopefully the older port
streams get garbage collected. I also did not have to parse through old
data at each run.

 

Thanks,

 

Ashis

 

________________________________

From: [email protected] [mailto:[email protected]]
On Behalf Of Raphael Collet
Sent: Wednesday, March 25, 2009 9:18 AM
To: Mozart users
Subject: Re: Global variable (Dictionary)

 

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

Reply via email to