c - FreeRTOS 信号量

标签 c semaphore freertos

这是 FreeRTOS api 引用的摘录 http://www.freertos.org/a00122.html关于 xSemaphoreTake() 函数:

// See if we can obtain the semaphore. If the semaphore is not available
// wait 10 ticks to see if it becomes free.
if( xSemaphoreTake( xSemaphore, ( portTickType ) 10 ) == pdTRUE )
{
// We were able to obtain the semaphore and can now access the
// shared resource.

我的问题是:我这里已经有了信号量还是必须调用 xSemaphoreTake( xSemaphore, (portTickType) 10 ) 明确如:

// We have finished accessing the shared resource. Release the
// semaphore.
xSemaphoreGive( xSemaphore );
}

最佳答案

在您链接到的示例中,在 if (...) 正文中采用了信号量。如果您从该示例复制粘贴,则由您来确保您的程序中同时具有 xSemaphoreTake 和 xSemaphoreGive。

关于c - FreeRTOS 信号量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14165218/

相关文章:

real-time - 优先级上限协议(protocol)如何工作

c - FreeRTOS 中队列数组的问题

c++ - 使用 volatile long 作为原子

c++ - 具有信号量同步的逻辑环形缓冲区

.net - 如何在.NET中创建可继承的信号量?

embedded - LPC 深度 sleep 模式示例

c - FreeRTOS - STM32F4 上的堆栈损坏

javascript - 用c语言创建登录功能cgi-html。(无PHP,Apache)

c++ - SDL 中没有可用的视频设备

c - 为性能设计服务器的最佳方法是什么?