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:

The remedy to the obstacle in the video can be located here:

Code for this video clip collection (consisting of obstacles, remedies, and demos) can be located right here:

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:

Relevant 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 –

Intro to RTOS Part 4 – Memory Management –

Introduction to RTOS Part 5 – Queue –

Intro to RTOS Part 6 – Mutex –

Intro to RTOS Part 7 –

Related Project Links:

Related Articles:

Find out more: –

Digi-Key’s Blog– TheCircuit

Get in touch with Digi-Key on Facebook

As well as follow us on Twitter

Leave a Reply

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