I’ve a program that basically has a matrix of cells(shared memory) and cars(observable threads). Before each movement each car asks for access to the next cell, and if the next is blocked it enters a synchronized block which calls wait(), and the thread goes to sleep. I was wondering if there was any way I could make the car do something while it’s on wait(), and then when he gets notified he can keep on doing what he was doing before the wait.
I’ve a program that basically has a matrix of cells(shared memory) and cars(observable threads).
Share
You’ll have to redesign: don’t model cars with threads. Have a thread pool perform any needed tasks and have an asynchronous model with callback functions guide the behavior of cars. If a cell is blocked, the state of the car simply doesn’t change and the thread pool can do something else. When the cell is freed, fire the appropriate callback, which will submit the update task to the pool.