Introduction to RTOS Part 10 - Deadlock and Starvation | Digi-Key Electronics
DigiKey DigiKey
152K subscribers
79,229 views
0

 Published On Mar 22, 2021

Starvation and deadlock are two common bugs that can occur in concurrent programming. Starvation happens when one one or more threads do not get a chance to run or do not get access to a shared resource because other (often higher priority) threads are hogging the CPU or resource.

The code for the Dining Philosophers challenge can be found here: https://github.com/ShawnHymel/introdu...

The solution to the challenge in the video can be found here: https://www.digikey.com/en/maker/proj...

Code for this video series (including demonstrations, challenges, and solutions) can be found here: https://github.com/ShawnHymel/introdu...

We can avoid starvation by ensuring that higher-priority tasks yield the processor periodically to allow lower-priority tasks a chance to run. Additionally, the higher-priority tasks should make sure to release any shared resources they might have to allow lower-priority tasks access to them.

We can also implement a technique called “aging” in a high priority task or in the scheduler itself. Aging gradually increases the priority of any task that has been in the blocked state for some period of time. Eventually, the task will reach the same priority level as the high priority tasks that are hogging the CPU/resource, and the previously low-priority task will get a chance to run. After performing its required actions, the low-priority task will have its priority downgraded to its original level to start the aging process again.

In the video, we provide the classic “Dining Philosophers” as an analogy to demonstrate starvation and deadlock. Deadlock occurs when all tasks are waiting on each other for a lock (e.g. mutex or semaphore) and no task is able to continue execution. Deadlock can result in system-wide failure and should be avoided at all costs.

We also give two possible solutions to the Dining Philosophers problem, including assigning a hierarchy to the locks as well as using a mutex to control access to the locks.

Product Links:
https://www.digikey.com/en/products/d...

Related Videos:
Introduction to RTOS Part 1 - What is a Real-Time Operating System (RTOS)? -    • Introduction to RTOS Part 1 - What is...  ​

Introduction to RTOS Part 2 - Getting Started with FreeRTOS -    • Introduction to RTOS Part 2 - Getting...  ​

Introduction to RTOS Part 3 - Task Scheduling -    • Introduction to RTOS Part 3 - Task Sc...  ​

Introduction to RTOS Part 4 - Memory Management -    • Introduction to RTOS Part 4 - Memory ...  ​

Introduction to RTOS Part 5 - Queue -    • Introduction to RTOS Part 5 - Queue |...  ​

Introduction to RTOS Part 6 - Mutex -    • Introduction to RTOS Part 6 - Mutex |...  ​

Introduction to RTOS Part 7 -    • Introduction to RTOS Part 7 - Semapho...  ​

Introduction to RTOS Part 8 -    • Introduction to RTOS Part 8 - Softwar...  

Introduction to RTOS Part 9 -    • Introduction to RTOS Part 9 - Hardwar...  

Introduction to RTOS Part 10 -    • Introduction to RTOS Part 10 - Deadlo...  

Introduction to RTOS Part 11 -    • Introduction to RTOS Part 11 - Priori...  

Introduction to RTOS Part 12 -    • Introduction to RTOS Part 12 - Multic...  

Related Project Links:
https://www.digikey.com/en/maker/proj...

Related Articles:
https://www.digikey.com/en/maker/vide...

Learn more:
Maker.io - https://www.digikey.com/en/maker

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

Connect with Digi-Key on Facebook   / digikey.electronics  

And follow us on Twitter   / digikey  

show more

Share/Embed