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: [ Ссылка ]
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: [ Ссылка ]
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:
[ Ссылка ]
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 [ Ссылка ]
Ещё видео!