FDR  4.2.7(6ecbe5a21b71ab020e8fcaeccfe5ebaad0599f4f)
Public Member Functions | Friends | List of all members
FDR::Canceller Class Reference

Allows cancellation of a running task to be requested. More...

#include <canceller.h>

Public Member Functions

 Canceller ()
 Creates a new canceller.
 
 Canceller (const Canceller &)=delete
 
void cancel ()
 Mark this canceller as cancelled. More...
 
bool cancelled () const
 Returns true if this canceller has been cancelled.
 
Cancelleroperator= (const Canceller &)=delete
 

Friends

struct CancellerHelper
 

Detailed Description

Allows cancellation of a running task to be requested.

Many of the tasks in FDR, such as checking a refinement assertion can be long-running, and thus may need to be cancelled before their natural completion. Cancellers allow this by supplying a cancel() method that requests cancellation of a certain task, which will endeavour to return as soon as it is safe to do so.

For example, a refinement assertion may be cancelled by using code similar to the following:

std::shared_ptr<Assertion> assertion = ...;
std::unique_ptr<Canceller> canceller(new Canceller());
std::thread refinement_thread([&canceller, assertion]){
try {
assertion->execute(canceller.get());
}
catch (const CancellerError&) {
std::cout << "Cancellation took place." << std::endl;
}
}
// .. perform some other task
// Cancel the refinement check
canceller.cancel();
// Wait for the cancellation to complete.
refinement_thread.join();

If you do not wish to allow for cancellation, then nullptr can always be passed to any function in place of a Canceller.

Member Function Documentation

◆ cancel()

void FDR::Canceller::cancel ( )

Mark this canceller as cancelled.

This is NOT safe to call from a signal handler.


The documentation for this class was generated from the following file:
FDR::Canceller::Canceller
Canceller()
Creates a new canceller.