Quality RTOS & Embedded Software

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


Loading

Question on xSemaphoreTake()

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

xSemaphoreTake(
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.

Thanks,
Siheng

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.

Siheng


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


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

Latest News

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

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

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


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

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