what are the rules u follow when u r writing critical
section of code?

Answer Posted / vinod

a) Use Atomic Instructions
b) Remember to enable interrupts
c) Make the critical section code as small as possible.
(Prefer not more than 20 instructions)
d) Prefer not to call other functions from the critical
section. if u r calling, see that there is no critical
section in the other function too. Critical section is
bounded by Disable Interrupt and Enable Interrupt.
Check the example below.
fnA()
{
/* Critical Section Start */
Disable_Interrupt();
Some Instructions A ....
Call FnB();
/* do Something B */
Some Instructions B ....
/* Critical Section End */
}


fnB()
{
/* Critical Section Start */
Disable_Interrupt();
Some Instructions ..
Enable_Interrupts();
/* Critical Section End */
}


Now the Enable_Interrupts in fnB() will enable the
interrupts and hence "Some Instructions B .." in fnA()
which should have been in critical section will no more be
in critical section because the interrupts are already
enabled!!

Please check if this condition is handled by the Enable and
Disable functions. If you want suggestions on how to solve
this problem, do revert back

Is This Answer Correct ?    10 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

No New Questions to Answer in this Category !!    You can

Post New Questions

Answer Questions in Different Category