nobody wrote on Thursday, May 18, 2006:
I don’t understand how a task can be allowed to yield from within a critical section. Isn’t the whole point behind a critical section to protect some “critical” piece of code?
For example, if I have two task that both use a shared resource, I am supposed to protect the use of that shared resource by using a critical section. If some OS call from within my critical section decides to yield, the other task will have an opportunity to use the shared resource. How can this work?
I do understand that the current architecture correctly maintains the interrupt enable status even through a yield inside a critical section, but how does this help?
Another example, I have two tasks, T1 and T2. Suppose T1 has a critical section of code during which interrupts cannot be allowed to run and further suppose that T2 currently has interrupts enabled. A yield is allowed during the critical section of T1, switching to T2. Now an interrupt occurs, and is serviced. I have just messed with the critical section of T1!
Please help me understand how this can work? What am I missing?