threading - parallel on both cores

hey there,

i’ve been trying to get Panda to use threads for quite some time now, but i can’t get it to work properly.

i’m using panda v1.7.0 compiled from source and i’ve set SIMPLE_THREADS to ‘UNDEF’, yet i can’t seem to get my second core to do anything.

the program is reading 3d coordinates from a file and displaying them as vertices (about 200k per frame). what i’ve been trying to do is get the camera navigation to run in the main thread and have the reading/drawing done in a separate one.

AsyncTaskManager *taskMgr = AsyncTaskManager::get_global_ptr();
AsyncTaskChain *chain = taskMgr->make_task_chain("readWriteChain");

taskMgr->add(new GenericAsyncTask("Rotates the camera", &CamRotationTask, NULL));
taskMgr->add(new GenericAsyncTask("Moves the camera", &CamMovementTask, NULL));

PT(GenericAsyncTask) vertexTask;
vertexTask = new GenericAsyncTask("drawsVertices", &DrawTask, NULL);


is there something else i need to do to get panda to run 2 threads parallel?


On Windows, you also have to set:

lock-to-one-cpu 0

in your Config.prc file.


thanks dude, works perfectly now!

Sorry for Topic Hijacking, but what is actually the current state of threading in Panda?
I know there were many discussions on this, but suporting multiple cores never had priority. Now that nearly all PCs have at least a dual core, I’d like to revive the topic.

It hasn’t much changed lately. The current state is:

(1) Python itself is single-processor only. If you want to take advantage of multiple cores, all but one of your threads has to be written in C++.

(2) When compiled with full threading support, Panda can load models in the background on a separate core.

(3) You can run your own C++ tasks on a separate core easily. (You can also run your Python tasks in a separate thread, but due to (1), they won’t run on a separate core.)

(4) As with any multiprogramming solution, you are responsible for avoiding race conditions and deadlocks when you write your own threads. This makes your programming problem much, much more difficult. We suggest you avoid explicit threads whenever possible.

(5) The long-term plan is to support rendering on multiple cores within Panda, basically meaning that the “cull” and “draw” tasks can each run on their own core, leaving one entire core for your application to use freely, and still allowing you to write easy single-threaded code. This is not yet fully implemented.