From the course: IoT Foundations: Operating Systems Fundamentals

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Thread safety

Thread safety

From the course: IoT Foundations: Operating Systems Fundamentals

Start my 1-month free trial

Thread safety

- [Instructor] In a multitasking environment, one concurrency problem you may experience is race condition. An OS usually provides interfaces in order to provide thread safety guarantees. The race condition happens when multiple tasks or threads try to access or change the shared data. Here we show an example scenario of two tasks attempting to access the shared data globally defined as an integer with initial value of one. Basically, Task One and Task Two can change A at any time. If Task One changes and uses the value in its task function, it will not get value it expected because, at any time, Task Two may change the value. This race condition is harmful to the program, which will introduce unexpected erroneous issues and bugs. To avoid this to happen, we need to make sure when accessing the shared data, it is thread-safe. Almost any operating system kernel includes the primitives for thread-safe operations on shared data. Let's look at a couple of common options here. First, we…

Contents