Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Question on xSemaphoreTake()

Posted by Siheng Huang on January 7, 2009
I have a question on freeRTOS semaphore function:

xSemaphoreHandle xSemaphore,
portTickType xBlockTime

freeRTOS document says: "A block time of zero can be used to poll the semaphore".
My question is what does the block time means and what happens after block time expires. There are two understandings:

1. The block time means the time period for task to poll the semaphore state. So after block time expires, the task continue to check if semaphore is available. If not, then task will check again after next block time expires.

2. The block is the max time task being block if the semaphore is not available. After block time expires, task will start to execute next instruction even if semaphore is not available.

Which understanding is correct?

if first understanding is correct, when using
xSemaphoreTake( xSemaphore, ( portTickType ) 0 ) in one of my task and the semaphore/mutex is not available for a long time, I guess the task being block continue to run trying to poll semaphore state? If so, will lower priority task be block? This seems to defeat the purpose of using semaphore.


RE: Question on xSemaphoreTake()

Posted by MEdwards on January 7, 2009
The block time is the maximum time the task will spend in the blocked state to wait for the semaphore. It does not execute at all when in the blocked state.

Take a look at the new book http://www.freertos.org/Documentation/FreeRTOS-documentation-and-book.html

RE: Question on xSemaphoreTake()

Posted by Siheng Huang on January 8, 2009
Thanks, MEdwards, that answers my question.


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS v10.2.0 is available for immediate download. MIT licensed, and including RISC-V and ARMv8-M (Cortex-M33) demos.

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Cadence Tensilica Cortes

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers





STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner