Quality RTOS & Embedded Software

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




Loading

Behaviour of nested calls to xSemaphoreTake with mutex in same task

Posted by pugglewuggle on December 22, 2015

If a task has already obtained a mutex will a calling xSemphoreTake on the same mutex in the same task (for example, in a function being called) succeed or fail?


Behaviour of nested calls to xSemaphoreTake with mutex in same task

Posted by rtel on December 22, 2015

A standard mutex can only be taken once, so nested calls to attempt to take a standard mutex will fail. This is quite easy for you to test, or determine from the code.

If you want the possibility to obtain the same mutex twice (at once) then you will instead need to create a recursive mutex.


Behaviour of nested calls to xSemaphoreTake with mutex in same task

Posted by pugglewuggle on March 2, 2016

To be clear, do I need to give that mutex the same number of times I take it?


Behaviour of nested calls to xSemaphoreTake with mutex in same task

Posted by richard_damon on March 2, 2016

If it is a non-recursive mutex, if you already have it, you shouldn't call take again.

If it is a recursive mutex, you need to give it as many times as you took it.

Note, recursive mutexes use xSemaphoreTakeRecursive/xSemaphoreGiveRecursive instead of the simple xSemaphoreTask and xSemaphoreGive.


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




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

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

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