指定任务myCpu1Task在cpu 1上运行:
STATUS affinitySetExample (void) { cpuset_t affinity; int tid; /* Create the task but only activate it after setting its affinity */ tid = taskCreate ("myCpu1Task", 100, 0, 5000, printf, (int) "myCpu1Task executed on CPU 1 !", 0, 0, 0, 0, 0, 0, 0, 0, 0); if (tid == NULL) return (ERROR); /* Clear the affinity CPU set and set index for CPU 1 */ CPUSET_ZERO (affinity); CPUSET_SET (affinity, 1); if (taskCpuAffinitySet (tid, affinity) == ERROR) { /* Either CPUs are not enabled or we are in UP mode */ taskDelete (tid); return (ERROR); } /* Now let the task run on CPU 1 */ taskActivate (tid); return (OK); }