FDR::Canceller Class Reference

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

#include <canceller.h>

List of all members.

Public Member Functions

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

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:

 {.cpp}
 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

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:
 All Classes Functions

Generated on 27 Oct 2017 for FDR by  doxygen 1.6.1