Passing Objects Between Threads -->
I am making a simulation in which objects are stored in a 2 dimentional array.
For the sake of this post you can think of the 2 dimentional array as being a soccer field and the objects in the array as the players.
When I first wrote this program each player acted one at a time. I just made a loop and called each players "act()" method on the field. This made things very easy.
I just pass the "field" object to each player via in the players "act()" method. So it would look like this --> player.act(field);
then each player knows exactly what is on the field and in what location. It then makes its move and passes the 2D array back to the field class and the updates are saved before passing the field on to the next player.
However, now I want each object (player) to run its own thread so every player on the field opperates independantly in real time.
Since each player is running its own thread I need a way to pass the field object to each player every time the field is updated, so every player is working from the latest field stats.
Ive been reading some tutorials about passing object between threads and saw some stuff about "piped input/output streams".
I am new to this technique and was wondering if this would work? Can I pass objects between the threads this way? I am hoping someone with more experiance can point me in the right direction. Maybe this is not the right approach. If anyone has any ideas on how to accomplish this please let me know.
thanks.