Semester : SEMESTER 6
Subject : Embedded System
Year : 2018
Term : MARCH
Scheme : 2015 Full Time
Course Code : EC 308
Page:56
९६८99 5 _.ٗ۔
2. Use reentrant functions with atomic instructions in that part of a funetion that needs ity com
execution before it can be interrupted. This part iy called the critical section, Poy ല്ലം
suboperations of shifting of x in Example 7.15 are in critical section ' the
3. Put a shared variable in a circular queue, A function that requires the 111110 أن thin variable ஞ்
deletes (takes) it from the queue front, and another function, Which 11130113 (Writes) the value af டி ۷۶۵ |
always does so at the queue back, Now ४ problem can ೧೮೪01 111 ease there ave a large ಇ
of functions that post the values into and take the values but the maximum required queue size is nog ۷۷ ய
Example 7.16
Example shows how shared data problem get solved by using queue, Consider the Example 7.1 5(h) 1
that variables 1 for time and ل for date are shared variables and there is a queue 11) ॥५ which + thread
inserts the shared variables and another thread deletes these variables, | Note: ബെ ലേ
writing a Value at the queue tail and then changing the pointer to the queue Gil for the next insertion,
Deletion from a queue means reading the value
from the queue head and then changing the pointer to the queue head for the next read.
1. Assume that when Update_Time_Date runs the | = 23:59:59 and date ५ = 17 July 2007 and inserts
these in a queue Qyp.
2. The Display_Time_Date reads t and ل from 01७ and displays. When the thread gets interrupted after
reading .ل display of .ل the 01915 still holding t when interrupt ب/ occurs, Display of t will complete
on return from the interrupt.
3. Aftera while, the tchanges to t = 00:00:00 and date ل = 18 July 2007 and the thread ( Ipdate_Time_Date
runs and inserts the new values of Cand ل at the back of the earlier values in டெடி, The -/ will
show d = 17 July 2007 and t = 23:59:59 and on return from the interrupt and in the next cycle
run the thread will show d = 18 July 2007 and t = 00:00:00.
The use of queue for the shared variables ل and | in two threads when Update_Time_Date inserts
these into the queue and Display_Time_Date deletes these from the (५७ causes no display error,
4. Disable the interrupts before a critical section starts executing and enable the interrupts on its completion,
It is a powerful but drastic option, An interrupt, even if of higher priority than the present critical function,
gets disabled. Advantage of it is that the semaphore functions have greater computational overhead than
disabling of the interrupt. The difficulty with this option is that it increases in the interrupt latency period for
all the tasks. The latency increases by the time taken in executing the codes of the section. A deadline may be
missed for an interrupt service by that task which does not share the critical section or the resource.
As an alternative to disabling interrupts, Section 7.7.2 described using of semaphores for the shared dala
problem. A software designer must not use the drastic option of disabling interrupts in all the critical 561083
[Note: In the OS for automobile applications, the disabling of interrupts is used before entering any “الاك
section to avert any unintended action because of improper use of semaphores.] Another alternative is ४ +
lock or spin-lock functions in a scheduler. (Section 7.11)
The use of disabling the switching of task from one to another and other steps and use of men
(Section 7.7) must eliminate the shared data problem completely from a multitasking, multi-ISRs and mu
shared variable cases. Each of the step has its own inherent benefits in solving the problem. A ۶
must utilize the various steps optimally suited to solve the problem.
Shared data problem can arise in a system when another higher priority task finishes an operation and mal
the data or a variable. Using reentrant functions, disabling interrupt mechanism, using semaphores نس
such as mailbox and queue are the solutions which are used for taking care of shared data problem.