二值信号量的使用例子Tornado

#include #include #include #define STACK_SIZE 0x1000void thisPrint(void); void thatPrint(void); SEM_ID sem1Sync; SEM_ID sem2Sync; int main() { sysClkRateSet(1000); //二值信号量,初始值不同 sem1Syc = semBCreate(SEM_Q_PRIORITY, 1); sem2Syc = semBCreate(SEM_Q_PRIORITY, 0); //多任务 taskSpawn("task1", 100, 0, STACK_SIZE, (FUNCPTR)thatPrint, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); taskSpawn("task1", 100, 0, STACK_SIZE, (FUNCPTR)thatPrint, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); while (1) { taskDelay(1); } return 0; }void thisPrint() { int thiscout = 0; while (1) { semTake(sem1Sync, WAIT_FOREVER); for (thiscout= 0; thiscout < 3; thiscout++) { printf("this->%d\n", thiscout); taskDelay(1); } semGive(sem2Sync); } }void thatPrint() { int thatcout = 0; while (1) { semTake(sem2Sync, WAIT_FOREVER); for (thatcout = 0; thatcout < 5; thatcout++) { printf("that->%d\n", thatcout); taskDelay(1); } semGive(sem1Sync); } }

【二值信号量的使用例子Tornado】

    推荐阅读