二值信号量
SemaphoreHandle_t sem_handle; sem_handle = xSemaphoreCreateBinary(); static void send_Task(void* pvParameters) { while(1) { xSemaphoreGive(sem_handle); vTaskDelay(1000); } } static void receive_Task(void* pvParameters) { while (1) { xSemaphoreTake(sem_handle, portMAX_DELAY); printf("接收二值信号量\r\n"); } }
计数信号量
SemaphoreHandle_t sem_count_handle; sem_count_handle = xSemaphoreCreateCounting(5, 5); static void send_Task(void* pvParameters) { while(1) { vTaskDelay(1000); xSemaphoreGive(sem_count_handle); } } static void receive_Task(void* pvParameters) { while (1) { xSemaphoreTake(sem_count_handle, portMAX_DELAY); printf("接收计数信号量\r\n"); } }
标签:handle,void,信号量,static,sem,pvParameters From: https://www.cnblogs.com/njit-sam/p/18112135