Quality RTOS & Embedded Software

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


Binary Semaphore runs on task initialising

Posted by phil on March 31, 2009

I have created a binary semaphore in my module initialization code:

vSemaphoreCreateBinary( xBinarySemaphoreRxMsg );

It initializes ok, I then create a new task to run:

xTaskCreate( vRX_MsgHandlerTask, "RX", MSG_TASK_STACK_SIZE, NULL, xTask_Priority, NULL );

All ok, here is the basic task code:

void vRX_MsgHandlerTask( void *pvParameters )
unsigned portSHORT i;
//unsigned portSHORT usFrameIndex;

ulMsgCounter = 0;

for( ;; )
//blocking for RX event to happen
xSemaphoreTake( xBinarySemaphoreRxMsg , portMAX_DELAY );

TRACE_sprintf("Processing the Data\r\n");

Now when the vRX_MsgHandlerTask starts for the first time the TRACE_sprintf("Processing the Data\r\n"); is called and outputs to the console. I am pretty sure there has been no call to xSemaphoreGive( xBinarySemaphoreRxMsg ); it is as if the binary semaphore thinks it can take the semaphore, the code runs as expected after this has happened.

Is this a school boy error, hope you can help.


RE: Binary Semaphore runs on task initialising

Posted by David Hawks on March 31, 2009
The semaphore starts out available to be taken (check out the definition of "vSemaphoreCreateBinary" in "semphr.h"). You must take it first outside of your task's loop if you don't want it to be available when your loop first runs.

RE: Binary Semaphore runs on task initialising

Posted by phil on March 31, 2009
Thanks for the quick response that fixed the problem. :)


[ 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.

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.


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


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