Print

Print


Hi Sean,
 
"multiple agents will not access the variable simultaneously 
unless you have fired them in separate threads.  In the standard 
MASON distribution, this is only possible via ParallelSequence or 
AsynchronousSteppable. "
 
I realize that now. Before that, I did implement a monitor as what you advised by using a lock. 
And since there isn't any need for atomicity, I redesigned my logic and now my agents are behaving as they should. 
 
Regards and Happy New Year,
Jimmy.

________________________________

From: MASON Multiagent Simulation Toolkit on behalf of Sean Luke
Sent: Fri 12/29/2006 11:34 PM
To: [log in to unmask]
Subject: Re: Synchronizing between Agents



Jimmy, multiple agents will not access the variable simultaneously 
unless you have fired them in separate threads.  In the standard 
MASON distribution, this is only possible via ParallelSequence or 
AsynchronousSteppable.  So you'll need to be more specific about what 
you mean here.

As to concurrent access control, Java does this like any other 
multithreaded system.  Create a lock variable that both agents have 
access to -- perhaps an instance variable.  An empty array works nicely:

        Object[] lock = new Object[0];

Then later your agents access the variable of choice like this:

        synchronized(lock)
                {
                // do stuff with my variable
                }

Sean

On Dec 25, 2006, at 3:28 PM, Jimmy Ong wrote:

> Merry Christmas to all!
>
> Can someone show me how do i prevent concurrent access to some 
> variable
> between 2 or more agents? I tried to synchronize on state.schedule 
> or an
> arbitrary object, but it doesn't work.
>
> Thanks in advance,
> Jim.