RTOS Question:
Download Questions PDF

What are the rules you follow when you are writing critical section of code?

Answer:

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

Download Real-Time Operating System (RTOS) Interview Questions And Answers PDF

Previous QuestionNext Question
What is the need of creating 4GB of pages in Linux?What are the advantages and disadvantages of winCE compared to GPOS?