13.07.2015 Views

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Mechanisms 2612.1 Disable interruptsMost computer architectures allow interrupts to be disabled, perhaps on a selective basis.If a device signals an interrupt while interrupts are disabled, the new interrupt will bepostponed until interrupts are again allowed. If activities are preempted only when aninterrupt occurs, exclusion can be enforced by disabling interrupts while any activity is ina region. Since no interrupts arrive, the current activity will be able to complete theinstructions in its region before any other activity starts executing in a conflicting region.Adjusting the interruptibility of the computer leads to a processor-synchronoustechnique for mutual exclusion. The BeginRegion and EndRegion procedures look likethis:1 procedure BeginRegion;2 begin3 DisableInterrupts;4 end BeginRegion;56 procedure EndRegion;7 begin8 EnableInterrupts;9 end EndRegion;Disabling interrupts can be quite fast. A single machine instruction often sufficesto change the interrupt state of the machine. However, this method has some unfortunateproperties.Once an activity has entered a region, real-time events, like devices that need service,cannot be treated until the activity has left the region. Therefore, lengthy processingin a region is usually unacceptable. This property is due to the fact thatdisabling interrupts is extremely conservative.It excludes not only potentially conflicting activities that might otherwise accessshared data but also all activities whatsoever, no matter what their purpose.One reason a region might be lengthy is that the program might have to wait forsome event before continuing. For example, the program might be waiting for adevice to become available. The programmer should not put waits inside regions.The technique fails on multiprocessors because it is usually not possible for a programon one machine to block interrupts on other machines. Even if interrupts canbe disabled on all machines, conflicting activities can still be executing simultaneously.The programmer must be careful to ensure that all paths from the region gothrough code to release exclusion by enabling interrupts once again. It is easy tooverlook some path and introduce a deadlock.<strong>An</strong>other pitfall involves nested regions. If procedure A calls procedure B frominside a region and B also enters a region, B will re-enable interrupts during itsEndRegion operation, relaxing exclusion before A was ready to do so. (See theexercises at the end of this chapter.)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!