#include <stdio.h>
#include <tasklib.h>
#include <semlib.h>
#define STACK_SIZE 0x1000
void 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()
{
二值信号量的使用例子Tornado
最新推荐文章于 2024-06-25 10:11:01 发布
本文介绍了如何在Tornado框架中使用C语言实现二值信号量,通过具体的代码示例展示了在嵌入式系统中如何进行资源同步和保护,以确保多任务环境下的正确运行。
摘要由CSDN通过智能技术生成