Skip to Content
Hands-On RTOS with Microcontrollers
book

Hands-On RTOS with Microcontrollers

by Brian Amos
May 2020
Intermediate to advanced
496 pages
13h 54m
English
Packt Publishing
Content preview from Hands-On RTOS with Microcontrollers

Avoiding mutex acquisition failure

While mutexes help to provide protection against some priority inversion, we can take an additional step to make sure the mutex doesn't become an unnecessary crutch. The section of code that's protected by the mutex is referred to as a critical section:

if(xSemaphoreTake(mutexPtr, 200/portTICK_PERIOD_MS) == pdPASS){    //critical section is here    //KEEP THIS AS SHORT AS POSSIBLE    xSemaphoreGive(mutexPtr);}

Taking steps to ensure this critical section is as short as possible will help in a few areas:

  • Less time in the critical section makes the shared data more available. The less time a mutex is being held, the more likely it is that another task will gain access in time.
  • Minimizing the amount of time low priority ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On RTOS with Microcontrollers - Second Edition

Hands-On RTOS with Microcontrollers - Second Edition

Jim Yuill, Penn Linder

Publisher Resources

ISBN: 9781838826734Supplemental Content