Here is a “simple” multithreading framework that I made based on concepts presented by Intel during their multithreading tutorial last GDC in San Francisco.
This basically implements a threadpool which processes tasks in a task queue every frame. What you just need to do is populate this task queue at the start of every frame. For example, fill it with AI tasks or physics tasks. Note that this framework still requires your code to handle critical sections properly.
** Implemented in Windows since I was having trouble compiling Panda3D in Snow Leopard.
Zip file also contains the Visual Studio 2008 solution.
I’m not entirely familiar with the taskChain method but was it also implemented with a threadpool or do the tasks run on their own separate threads?
I implemented my framework specifically to take advantage of multithreading and at the same time minimize context switching since the processor can only run a certain amount of threads simultaneously. At least that’s what I wanted to do conceptually…
Hmm… Panda3D ran fine but I had trouble compiling C++ source code with Panda3D. It gave me 6000 errors in XCode.
Right, a TaskChain has its own thread pool. You specify this with the numThreads parameter to taskMgr.setupTaskChain(). Regretfully, the manual page that describes task chains and the parameters you can apply has yet to be written by me, so it’s not at all surprising that you’re not familiar with it.
I’m not quite sure what this means–how do you minimize context switches with user space code? The context switch is entirely the province of the threading implementor, isn’t it? That is, the OS decides when to make a context switch, you have no control over that.
I understand that the OS decides context switching and I have no control over that. I just wanted to implement the basic concepts of the thread pool. The Intel tutorial used their own threading libraries (Intel Threading Blocks if I remember correctly) so they must have some control over this.