Game Development Reference
In-Depth Information
TaskSetAHandle = CreateTaskSet(
TaskSetAFunction ,
NumberOfTasksInA ,
NoDependecies);
TaskSetBHandle = CreateTaskSet(
TaskSetBFunction ,
NumberOfTasksInB ,
TaskSetAHandle);
/* Other processing on the main thread.
The tasking system will
execute taskset A then taskset B.
WaitForTaskset will not return
until taskset B is complete. */
WaitForTaskSet( TaskSetBHandle );
// Consume data produced by taskset B that.
Listing 17.2. Specifying dependencies.
(see Listing 17.2). The main thread can then continue executing while the tasking
system instantiates taskset B when the dependencies for B are met.
When waiting means working. WaitForTaskSet does not actually wait in the OS
sense. Blocking a thread that participates in the tasking system would be inecient.
Rather, WaitForTaskSet notifies the tasking system that the main thread cannot
proceed until the specified taskset completes its work. As part of WaitForTaskSet ,
the main thread will start processing tasks itself until the taskset it is waiting on
completes. That way, the main thread is drafted into being a worker thread when
no other useful work can occur on the main thread.
Generally, tasking systems will create
N −
1 OS threads, where
N
is the num-
ber of hardware threads on the machine. Creating
threads would compete for
execution time with the main thread whenever work was executing in the tasking
system. Also tasks should never block, meaning they should not call any function
that might put the OS thread to sleep. The tasking system only creates one OS
thread per CPU core. If one of those threads block, there is no other OS thread
available within the tasking system to continue processing tasks. As a result, per-
formance will be lower, as one CPU core will be unused until the blocking condition
is resolved.
N
17.2.2 Code with Data Dependencies
Task parallelism works by exploiting the property of data independence between
tasks. If a system does not have that property, tasking is more challenging. For
example, an AI system with a collision detection algorithm for models moving on a
Search WWH ::




Custom Search