I have a two-dimensional cellular automata. In some cells there may be an actor (agent). Each actor is a thread. I need to move actor based on the 9 cells around the actor's cell. I want to do this concurrently so the actor in a cell (4,5) can use neighbors cells (3,4), (4,4), (5,4), (3,5), (5,5), (3,6), (4,6), (5,6) and no other actors can use this cells. If some actor has these cells in his neighborhood, he has to wait until the first actor moved. But I want to allow moving the actor, who has no common neighborhood, concurrently. So the actor in (4,5) can move at the same time as an actor in (10,5) because they have no common neighborhood.
What is the best solution of that? Can you propose something?
The rough idea is below.
Note that the cell, from which Actor starts to move, is not protected in the code below. Also, what would you expect if every cell is populated has an Actor?