A mutex, short for MUTual EXclusion, is a locking mechanism that is used to prevent other threads from interrupting or overwriting a section of shared data (such as a global variable or common buffer).
The solution to the challenge in the video can be found here: [ Ссылка ]
Code for this video series (including demonstrations, challenges, and solutions) can be found here: [ Ссылка ]
FreeRTOS implements mutexes and semaphores with queues, and operations to read, increment, and decrement these kernel objects are all atomic (meaning other threads cannot interrupt or modify the variables during those operations).
We use a mutex as a locking mechanism to protect a shared resource or critical section of code. When a thread or task takes a mutex, the value of the mutex is decremented from 1 to 0, and other tasks may not take the mutex while it is 0.
When the task is done working in the critical section, it gives the mutex back, which increments it from 0 to 1. This action of taking and giving a mutex allows only one thread to operate in a critical section of code at a time (it is mutually exclusive: no other threads may execute that section or take the mutex during that time).
In the video, we give an example of a race condition and how a mutex can be used to prevent it from happening. We provide a demonstration of using a mutex in FreeRTOS and then issue a challenge to use a mutex to allow parameters to be passed to tasks (note: this is a hack!).
Product Links:
[ Ссылка ]
Related Videos:
Introduction to RTOS Part 1 - What is a Real-Time Operating System (RTOS)? - [ Ссылка ]
Introduction to RTOS Part 2 - Getting Started with FreeRTOS - [ Ссылка ]
Introduction to RTOS Part 3 - Task Scheduling - [ Ссылка ]
Introduction to RTOS Part 4 - Memory Management - [ Ссылка ]
Introduction to RTOS Part 5 - Queue - [ Ссылка ]
Introduction to RTOS Part 6 - Mutex - [ Ссылка ]
Introduction to RTOS Part 7 - [ Ссылка ]
Introduction to RTOS Part 8 - [ Ссылка ]
Introduction to RTOS Part 9 - [ Ссылка ]
Introduction to RTOS Part 10 - [ Ссылка ]
Introduction to RTOS Part 11 - [ Ссылка ]
Introduction to RTOS Part 12 - [ Ссылка ]
Related Project Links:
[ Ссылка ]
Related Articles:
[ Ссылка ]
Learn more:
Maker.io - [ Ссылка ]
Digi-Key’s Blog – TheCircuit [ Ссылка ]
Connect with Digi-Key on Facebook [ Ссылка ]
And follow us on Twitter [ Ссылка ]
![](https://i.ytimg.com/vi/I55auRpbiTs/maxresdefault.jpg)