Let's say i have a Domain Model that im trying to make compatible with multithreading. The prototype domain is a game domain that consists of Space, SpaceObject, and Location objects. A SpaceObject has the Move method and Asteroid and Ship extend this object with specific properties for the object (Ship has a name and Asteroid has a color)
Let's say i want to make the Move method for each object run in a seperate thread. That would be stupid because with 10000 objects, i would have 10000 threads. What would be the best way to seperate the workload between cores/threads?
I'm trying to learn the basics of concurrency, and building a small game to prototype a lot of concepts.
What i've already done, is build a domain, and a threading model with a timer that launches events based on intervals. If the event occurs i want to update my entire model with the new locations of any SpaceObject. But i don't know how and when to launch new threads with workloads when the event occurs.
Some people at work told me that u can't update your core domain multithreaded, because you have to synch everything. But in that case i can't run my game on a dual quadcore server, because it would only use 1 CPU for the hardest tasks.
Anyone know what to do here?
Specification in reaction to Deltreme:
You are absolutly right, and your method will work in most cases. BUT, The threads have to update the location of the spaceobject in the Space class.
Let's say i have 2 SpaceObjects next to eachother, they are moving towards eachother. 1 Object is in thread A, the other is in thread B. Once i update the objects the threads have to write to the Space together to write the new values in the Tile (an individual part of Space). That individual call cannot be done in different threads at once, cause the Space object would burst...
What could happen is a collision, and i could write an Event that occurs if their are 2 ships @ 1 tile. That's not the problem.
I'm thinking that in the case of 10000 ships, the CPU would primarily be switching between threads and not running them all togheter. So in the interest of performance, i want to be able to to "everything" simultaniously