First of all: Hi.
Since the last developer forum I was active in has been bought and pulverized by some people I've never entered a forum again for a while.
Now a year later I am confident again and hope to have found a new forum right here for now and the future.
> The basic architecture
1. I'm working on a Android game project using multithreading.
2. The game has several game loops i.e. a "logic loop"
3. Every loop has it's own "unit" memory to iterate through
> The problem
When creating a new "unit" while the game is running (i.e. a tank was produced in a factory -> this example happens in the logic-thread/loop) I need to make the reference of the tank known to the other threads by saving the reference in their "unit memory" (a list or a set).
Of course this would terminate the program with an error, since you can't modify a list while at the same time iterating over it.
My first solution was to synchronize the lists and make them thread safe. This however leads to the problem that it makes first of all the whole code significantly a lot slower and the thread adding the new objects had to wait for every thread to finish iterating causing the whole game to stuck a few ms when a new unit was created.
Has anyone an idea how I could possibly solve this multithreading issue?
Thank you very much
Edited by IceCave, 21 March 2014 - 03:07 PM.