INTERRUPT(3C++)

NAME
interrupt Interrupt_handler - signal handling for the task library

SYNOPSIS

#include <task.h>

class Interrupt_handler : public object {
public:
	// exported constructor
	Interrupt_handler(int signo);

	// exported virtual function
	virtual int pending();

private:
	// private virtual function
	virtual void interrupt();
};

DESCRIPTION

Class Interrupt_handler provides a way for a task to wait for an external Unix signal. It is derived from class object so that tasks may wait on a handler object.

Interrupt_handler ih(signo);
    Constructs a new interrupt handler ih, which will wait for signal number signo (see signal(2)). When that signal occurs, the private virtual function interrupt() is called immediately, via the usual Unix signal mechanism. When the function returns, the task which was interrupted resumes. That is, interrupts do not cause preemption within the task model. A special task, the interrupt alerter, is automatically created by the task system. When a running task is suspended and an interrupt has occurred since the last task suspension, the interrupt alerter is scheduled. The alerter alerts the Interrupt_handlers associated with any interrupts which have occured since the last time the alerter ran. Any tasks waiting for such handlers therefore become runnable. In the absence of any interrupt handlers, the scheduling process terminates when there are no more tasks to be run. So long as there are any interrupt handlers, scheduling will not terminate, but will wait indefinitely for any interrupts which may occur.

int i = ih.pending();
    Always returns ``true'' (non-zero) except the first time it is called after an interrupt occurs.

void interrupt()
    This is a private virtual function. The base-class version does nothing. Normally you will derive a class from Interrupt_handler and define this function to do whatever is appropriate for that class. See the tutorial for an example.

DIAGNOSTICS

See task(3C++).

SEE ALSO
TASK.INTRO(3C++), queue(3C++), task(3C++), tasksim(3C++), signal(2)

Task Library Tutorial