包括任务函数使用全局变量和添加互斥量避免“冒险与竞争”
1 2 3 4 5 6 7 8 9 10 11 12 13
| SemaphoreHandle_t xMutextheTestTask = NULL; TickType_t timeOut = 1000; xMutextheTestTask = xSemaphoreCreateMutex();
void theTestTask(void *pvParam) { if (xSemaphoreTake(xMutextheTestTask, timeOut) == pdPASS) { xSemaphoreGive(xMutextheTestTask); } }
|
使用到的函数
1 2 3 4 5 6 7 8
| xSemaphoreCreateMutex();
xSemaphoreTake(xMutextheTestTask, timeOut);
xSemaphoreGive(xMutextheTestTask);
|