Blocking and shutdown handling

SPL provides functions to block and shut down operator processing elements safely.

Blocking and shutdown handling are two related topics. Blocking for a long time is often problematic, as it might interfere with shutdown handling. When a PE is asked by the runtime system to terminate, it needs to cooperate in a timely manner by requesting that all operators it contains terminate and wait for that to happen. Failing to do so results in a forced termination of the processing element.

To block safely, SPL provides several functions through the ProcessingElement class. A processing element is a container that manages the execution of the operators. To get access to the processing element object from within an operator, the getPE() function of the Operator class can be used. The blocking functions that are provided by the processing element are as follows:

void blockUntilShutdownRequest() const;
bool blockUntilShutdownRequest(double const timeInSeconds) const;
bool blockUntilShutdownRequest(timespec const absoluteTime) const;

The first function blocks until a shutdown request is received. The second and third functions are similar, but they unblock if a specified amount of time passes or an absolute time deadline is reached. The functions return true if the unblocking was due to the shutdown request, and false otherwise. It is important to note that the resolution of these functions is limited and dependent on the operating system. They might block more than the specified amount of time or past the specified deadline, when a very brief amount of blocking is requested.

To check whether a shutdown request is received by the processing element, the following function that is provided by the processing element object can be used:

bool getShutdownRequested() const;

This function is especially useful for creating source operator loops, where the loop iterates until the shutdown is requested.