Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
03/03/08 15:10
Modified:
  03/03/08 15:11

Read: times


 
#151811 - JBC as mutex
Responding to: ???'s previous message
Can you elaborate on what u meant?

Well, if you use JBC to implement a mutex (either the criticial section runs, or an interrupt runs), then the interrupt service routine will still get called if the interrupt occurs during the execution of the critical section (since interrupts were not disabled).

This is the first problem with this approach - the critical section still gets interrupted.

Then the interrupt service routine will check for the availability of the mutex. This will, of course, fail if the program was in the critical section. Now the interrupt service routine doesn't have many options:

1. It cannot just "sit there" and wait for the mutex to become available, since it has a higher priority than the "critical section" and will therefore simply sit in an endless loop while the critical section never finishes.

2a. It can just return from the interrupt without doing what it is supposed to do. Which is usually not what interrupts are for - they are for things that need to be taken care of ASAP.

2b. It can set some sort of flag indicating that it tried to get the mutex and failed. The critical section could, at the very end, evaluate this flag and take some action to resolve the situation. To me, this appears to be a fairly ugly hack.


The straightforward approach to implementing a critical section is disabling the interrupts. This should work for 99.999% of the situations where critical sections are necessary. If you think that it will not work for your problem, then the first question you need to ask yourself is not "What other options are there?" but "Why does disabling the interrupts not work here and what could I do to make it work?".

List of 6 messages in thread
TopicAuthorDate
Reposted: Critical section implementation on 8051?            01/01/70 00:00      
   JBC as mutex            01/01/70 00:00      
      why ugly?            01/01/70 00:00      
         atomicity and IE            01/01/70 00:00      
         Because ...            01/01/70 00:00      
            "short interrupts" is just another paradigm...            01/01/70 00:00      

Back to Subject List