Main Menu

Multi threading

Started by Qudus, January 15, 2008, 23:04:38

Previous topic - Next topic

Qudus

What is the best way to do multi threading? I would like to utilize both cores of a common dual code CPU for rendering. I once read, that OpenGL rendering can be done asynchronous. While OpenGL renders you can do other things like frustum culling, physics simulation etc.

I would do it as follows:
1. Create a new Thread (R) for the render context and create the context from within that thread.
2. Create a second thread (C) or use the main application's one for the other work like frustum culling or physics simulation.
3. Suspend thread R (put it to sleep to wait for the notify() method to be called)
4. Prepare the render atoms to be rendered by the context thread within thread C.
5. Check, if Thread R is currently asleep. Wait until it sleeps (finished the last frame). Wake it up.
6. continue with (4.)

Well, this is a very raw description. But you might get, what I mean. Does anybody have experience with it or any good links?

Marvin

Matzon

usually a common strategy is have 1 thread doing OpenGL and N threads doing AI, Sound, Game Logic etc etc.
Or in other words, its usually easiest to split up into specific domains and then use 1 thread per domain, or 1 thread per multiple domains. Its usually not worthwhile (or at least its very hard to get it working correctly) to have multiple threads per domain.