interrupt

© 2015 John Abbott
GNU Free Documentation License, Version 1.2



CoCoALib Documentation Index

Examples

User documentation

This file offers the 1-ary procedure CheckForInterrupt which takes a string (indicating the "context" of the call). It does nothing unless the interrupt flag has been set, in which case it throws a CoCoA::InterruptReceived. Normally it makes sense to call CheckForInterrupt only inside loops which may take a long time to complete.

The identity of the interrupt flag is given to the GlobalManager. If no flag has been specified then CheckForInterrupt will never throw.

Constructors and pseudo-constructors

An object of the class InterruptReceived is thrown an exception when an interrupt has been detected (by calling CheckForInterrupt). The class has no data members or member functions apart from those inherited from exception.

Its destructor has the side-effect of resetting the interrupt flag.

Maintainer documentation

See also the documentation for GlobalManager.

The implementation is extremely simple. CheckForInterrupt does nothing unless an interrupt flag has been specified to the GlobalManager and the flag has been set, in which case it throws a InterruptReceived object (passing the context string as constructor arg).

CheckForInterrupt is not inline because I do not think it needs to be.

The InterruptReceived object keeps its data in the exception subobject: this data is a message saying "External interrupt", and a context string (as given to the call to CheckForInterrupt, and which should indicate the location of that call).

The only "tricky" part is that its destructor resets the interrupt flag if one has been specified.

Bugs, shortcomings and other ideas

JAA is slightly uneasy about the "tricky" destructor which resets the interrupt flag (but cannot see how it could cause trouble).

Main changes

2015