Protecting Data and Synchronizing Tasks
What do race conditions, corrupt data, and missed real-time deadlines all have in common? Well, for one, they are all mistakes that can be easily made when operations are performed in parallel. These are also mistakes that are avoidable (in part) through using the right techniques.
This chapter covers many of the RTOS primitives that are used to synchronize tasks and protect shared data. The explanations in this chapter contain example-code, and analysis performed using Ozone and SystemView.
First, we will explore the differences between semaphores and mutexes. Next, you will understand how, when, and why to use a semaphore. You’ll also learn about race conditions and see how a mutex can avoid such situations. Example code will be provided throughout. The concept of race conditions will be introduced and fixed using a mutex in live code that can be run and analyzed on the Nucleo development board. Finally, FreeRTOS software timers...