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 Mutex and ConditionVar classes. 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 Panda's Thread and Mutex classes, and not any system thread or mutex objects. See Threading for more. Defining task chainsTo set up a new task chain, you simply call: AsyncTaskManager *task_mgr = AsyncTaskManager::get_global_ptr(); Each task chain must have a unique name. If you pass a name to make_task_chain() that has already been used, it will return the same pointer that was returned previously. Once you have a task chain pointer, you may then set parameters on that instance to configure the chain according to your needs.
The task chain parameters are:
Using task chainsYou may add any tasks to the task chain of your choosing by using AsyncTask::set_task_chain(). This method should receive the string name of the task chain to add the task to; this is the "chain_name" you specified in the above call to task_mgr->make_task_chain(). For example: PT(AsyncTask) task = new GenericAsyncTask("myTaskName");
© Carnegie Mellon University 2010 |