Semester : SEMESTER 6
Subject : Embedded System
Year : 2018
Term : MARCH
Scheme : 2015 Full Time
Course Code : EC 308
Page:57
18.3 Applications of Semaphores and Shared Data Problem 7
೭01 110103 facilitates mutually exclusive access by (Wo or more
‘ ۴ 801111, 15 shared between the various proce ^
iti ⋅− بات ॐ |,
1. Process | proceeds after sEm_m decreases and equals 0 and pets the exclusi
2. Process कन after ساس Increases and equals |: process 2 now می uaive access to the CPU.
3, Process 2 proceeds after sem m decreases and equals 0 and gets ದ عد و ५ pean عقنت
4 Process 2 ends after sem_m increases and equals 1; process | now gets the ex 7 ಗ : anu
The നട like a resource key and shared data within the processes | and 28 we ட ல்
first decreases it to 0 at the start gets the access to and prevents the other - مو न )
Processes to the resource (CPU). The same
५५८५. Le 0 a
{ process | and process 2 share sem_m and its
Mutex is 48 phore that provides at an instance two tasks mutually exclusive access to resources and is
عون in solving shared data problem.
7.8.4 Elimination of Shared Data Problem
The use of semaphores does not eliminate the shared data problem completely. Software designers may not
take the drastic option of disabling interrupts in all the critical sections by using semaphores. When using
semaphores. the OS does not disable the interrupts. Alternatively, task-switching flags can be used
(Section 8.10.3). The following problems that can arise when using semaphores.
1. Sharing of two semaphores creates a deadlock problem (Refer to Section 7.8.5).
2. Suppose the semaphore taken is never released? There should therefore be some time-out mechanism
after which the error message is generated or an appropriate action taken. There is some degree of
similarity with the watchdog timer action on a time-out. A watchdog timer on timeout resets the
processor. Here, after the time out, the OS reports an error and runs an error-handling function. Without
a time out, an ISR worst-case latency may exceed the deadline.
3. A semaphore not taken, and another task uses a shared variable.
4. What happens when a train takes a signal for a wrong track? When using the multiple semaphores, if
an unintended task takes the semaphore, it creates a problem.
5. There may be priority inversion problem (Refer to Section 7.8.5).
7.8.5 Priority Inversion Problem and Deadlock Situations
a and J does not share data with K. Also let tasks
1 ೩76 K alone share a semaphore and not J. Why do only a few tasks share a semaphore? Can't all share a
semaphore? The reason is that the worst-case latency bec
tasks are blocked when one task takes a semaphore. The wors he me
taken by the tasks that share the resources is relevant. Now consider the following situation.
At an instant டி, suppose task K takes a semaphore, the OS does not block task J and blocks task 1. This
ns because only tasks / and K share the data and J does not. C onsider the poem that now arises on
Selective sharing between K and 1. At the next instant t,, let task K become ready to run first on an interrupt.
Now, assume that at the next instant டி, task / becomes ready on an interrupt. At this instant, Kis in the critical
Section. Therefore, task / cannot start ‘at this instant due to K being in the critical region. Now, if at next instant
جا Some action (event) causes the unblocked higher than the K priority task J to run. After instant ہوا running
task J does not allow the highest priority task 110 run. This is because even though & is not running and thus