Attaching or Detaching an Interrupt

The attach statement associates an interrupt with an event. If the interrupt is already attached to another event, it is automatically detached from the old event and then attached to the new event.

You can attach each interrupt to only one event. However, you can attach more than one interrupt to the same event. When the event is caused, the associated interrupts are queued for execution in the reverse of the order that they were attached to the event.

It is possible to attach an interrupt to an event that is declared in a different process. The interrupt executes as part of the process that declared it, even if it is associated with an event in a different process. The interrupt declaration cannot be more global than the event declaration, or an “UP LEVEL ATTACH” error results. This error occurs at compile time if the compiler detects the problem. Otherwise, it occurs at run time.

The detach statement removes the association of an interrupt with an event. If the interrupt is not currently associated with an event, the detach statement has no effect and execution continues normally.

Note that if the interrupt is disabled, queued instances of the interrupt might have accumulated. Detaching the interrupt, or attaching the interrupt to a different event, causes these queued instances to be deleted. You can prevent this problem by enabling the interrupt before detaching it from an event or attaching it to a different event.

The following are ALGOL statements that attach and detach an interrupt. The first statement attaches the interrupt INT1 to the event E1. The second statement implicitly detaches the interrupt and then attaches it to the event E2. The third statement then detaches the interrupt and leaves it detached.

ATTACH INT1 TO E1;
ATTACH INT1 TO E2;
DETACH INT1;

The following COBOL statements attach two interrupts to the same event and then detach them:

ATTACH INT-1 TO E1.
ATTACH INT-2 TO E1.
DETACH INT-1, INT-2.