Amazon Video

Introduction to RTOS Part 7 – Semaphore | Digi-Key Electronics

A semaphore is a signaling device made use of to synchronise 2 or more strings. Similar to a mutex, it can be used to shield shared sources. In this video, we reveal you how to make use of semaphores with FreeRTOS on an ESP32 to pass information in between tasks.

The beginning code for the challenge can be found below: https://github.com/ShawnHymel/introduction-to-rtos/blob/main/07-semaphore/esp32-freertos-07-challenge-counting-semaphore/esp32-freertos-07-challenge-counting-semaphore.ino

The remedy to the obstacle in the video can be located here: https://www.digikey.com/en/maker/projects/introduction-to-rtos-solution-to-part-7-freertos-semaphore-example/51aa8660524c4daba38cba7c2f5baba7

Code for this video clip collection (consisting of obstacles, remedies, and demos) can be located right here: https://github.com/ShawnHymel/introduction-to-rtos

If some resource is not offered for usage, a semaphore is comparable to a mutex in that it is a locking mechanism used to tell jobs to wait. However, semaphores are a lot more than an easy lock: they can count to even more than 1 and also can therefore allow several threads to enter an important area of code.

In technique, nonetheless, we often do not wish to allow several strings adjust shared data, as well as we would still need to safeguard that data (or shared resource) with something like a mutex. We utilize semaphores as a signaling mechanism to inform various other threads when it is secure to access a resource or read brand-new data.

A barrier or linked checklist can be written to by a variety of “manufacturer” strings. Each time among these producer threads adds data to this resource, it increments a semaphore, which is just a counting variable that can be accessed atomically. When a “consumer” thread wants to check out data from the source, it decrements the semaphore matter. If the semaphore is 0, that indicates no new data is available, so consumer strings must wait (e.g. go into the blocked state).

Semaphores function in a similar way to mutex, however are typically used in various situations. We supply examples of these usage instances in the video along with problem a difficulty to make use of semaphores by yourself.

Item Links:
https://www.digikey.com/en/products/detail/adafruit-industries-llc/3405/7244967

Relevant Videos:
Introduction to RTOS Part 1 – What is a Real-Time Operating System (RTOS)? – https://youtu.be/F321087yYy4

Introduction to RTOS Part 2 – Getting Started with FreeRTOS – https://youtu.be/JIr7Xm_riRs

Introduction to RTOS Part 3 – Task Scheduling – https://youtu.be/95yUbClyf3E

Intro to RTOS Part 4 – Memory Management – https://youtu.be/Qske3yZRW5I

Introduction to RTOS Part 5 – Queue – https://youtu.be/pHJ3lxOoWeI

Intro to RTOS Part 6 – Mutex – https://youtu.be/I55auRpbiTs

Intro to RTOS Part 7 – https://youtu.be/5JcMtbA9QEE

Related Project Links:
https://www.digikey.com/en/maker/projects/introduction-to-rtos-solution-to-part-7-freertos-semaphore-example/51aa8660524c4daba38cba7c2f5baba7

Related Articles:
https://www.digikey.com/en/maker/videos/shawn-hymel/getting-started-with-stm32-and-nucleo-part-3-how-to-run-multiple-threads-with-cmsis-rtos-interface

Find out more:
Maker.io – https://www.digikey.com/en/maker

Digi-Key’s Blog– TheCircuit https://www.digikey.com/en/blog

Get in touch with Digi-Key on Facebook https://www.facebook.com/digikey.electronics/

As well as follow us on Twitter https://twitter.com/digikey

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.