To process a logical piece of work, we will declare the iTask
class with the Run()
method, which can perform a time-consuming operation. The declaration of the class is somewhat visually similar to iThread
. However, its instances implement some reasonably short operation and may be executed in different threads:
class iTask: public iIntrusiveCounter { public: iTask() : FIsPendingExit( false ) , FTaskID( 0 ) , FPriority( 0 ) {};
The pure virtual method Run()
should be overridden in subclasses to do the actual work:
virtual void Run() = 0;
The following methods optionally cancel the task and are similar to the ones in the iThread
class. Their purpose is to signal the hosting thread that this task should be cancelled:
virtual void Exit() { FIsPendingExit = true; } virtual bool IsPendingExit() const volatile { return FIsPendingExit; }
The GetTaskID()
and SetTaskID()
methods access the internal unique identifier of the task...