Quality RTOS & Embedded Software

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


Loading

problem with semaphore

Posted by Nobody/Anonymous on March 10, 2006
hi,
look at the following sample code:

while(1)
{
if(xSemaphoreTake(semaphore1,portMAX_DELAY)
==pdTRUE)
break;
else
vTaskDelay(1);
}

Obviously, the vTaskDelay(1) shoudn't be executed.

In my case, is executed!!

Can someone help me?
I am using arm7 at91sam7a3 cpu.

Thenks a lot.
Bye

RE: problem with semaphore

Posted by Nobody/Anonymous on March 10, 2006
There was a thread about this recently. You might want to look it up.

It can be that you block waiting to get a semaphore. The semaphore becomes available and unblocks the task. Because of the prioritization of your tasks the unblocked task although now able to run does not run before another task has again taken the semaphore. When the unblocked task does run it finds the semaphore already gone again and returns false.

There are a couple of ways around this. Change the prioritisation of your tasks so this cannot happen. Change the test to see if a switch should happen to say a switch occurs if a woken task has a priority greater or equal to the current task (by default a switch is performed if the woken task is *greater* than the current task only). Finally put the call to xSemaphoreTake within a while statement as:

while( xSemaphoreTake(semaphore1,portMAX_DELAY) != pdTRUE );

The while will only exit when the semaphore was successfully taken no matter what the other priorities within your system.

RE: problem with semaphore

Posted by Nobody/Anonymous on March 13, 2006
Using the 'while' solution it seems working!!

Thank you a lot for your time.
Bye.


[ 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