Panda3D Manual: Task ChainsWhen you add tasks to the TaskManager, you are actually adding them to the default Task Chain. The TaskManager maintains one or more task chains; each chain is a list of tasks that are available to be executed. You are free to create additional task chains as you see the need. Normally, though, there is no reason to have more than the default task chain, unless you wish to take advantage of threaded tasks: each task chain has the option of being serviced by one or more sub-threads, which allows the tasks on that chain to run in parallel with (or at a lower priority than) the main tasks. Note that threading is an advanced topic, and the use of threading inherently comes with risks. In particular, it is easy to introduce race conditions or deadlocks in code that involves multiple threads. You are responsible for protecting critical sections of your code from mutual access with proper use of synchronization primitives, such as provided by Panda's direct.stdpy.threading module. For the purposes of this discussion, we will assume that you are already familiar with the proper use of synchronization primitives in threading. Note also that Panda may be compiled with a special threading mode (called "simple threads") that is designed to be low overhead, but which is fundamentally incompatible with true threads as provided by the system library. Thus, in any Panda application, you must always use Panda's synchronization primitives, and not the system-provided ones; and you must use Panda's thread primitives and not call into the system thread library directly, or you will risk a terrible crash. That is, you should use direct.stdpy.threading and not the standard threading module. See Threading for more. Defining task chainsTo set up a new task chain, you simply call: taskMgr.setupTaskChain('chain_name', numThreads = None, tickClock = None, Task chains are identified by their unique name. Repeated calls to setupTaskChain() with the same task chain name will reconfigure the same task chain. The task chain parameters are:
Using task chainsYou may add any tasks to the task chain of your choosing with the optional taskChain parameter to taskMgr.add() or taskMgr.doMethodLater(). This parameter should receive the name of the task chain to add the task to; this is the 'chain_name' you specified in the above call to taskMgr.setupTaskChain(). For example: taskMgr.add(self.myTaskFunc, 'myTaskName', taskChain = 'myChain')
© Carnegie Mellon University 2010 |