PRunnable Class Referenceabstract

Detailed Description

The PRunnable class is an interface to inherit to get a task that will be executed by a concurrent thread.

The class must define a method of no arguments called Run().

Definition at line 29 of file PConcurrentThread.h.

#include <PConcurrentThread.h>

Constructor & Destructor Documentation

◆ ~PRunnable()

virtual PRunnable::~PRunnable ( )
inlinevirtual

Destroys this object.

Definition at line 35 of file PConcurrentThread.h.

Member Function Documentation

◆ Run()

virtual void PRunnable::Run ( )
pure virtual

When an object implementing interface PRunnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.

Example:

#include <PapillonCore.h>
USING_NAMESPACE_PAPILLON
class MyTask : public PRunnable {
public:
MyTask() {}
virtual void Run() {
for (int i=0; i<10; ++i) {
std::cout << "Iteration " << i << std::endl;
PConcurrentThread::Sleep(1000); // wait for 1 second
}
}
};
int main() {
MyTask myTask;
// create and start a concurrent thread that will execute myTask.Run()
PConcurrentThread thread(myTask);
// waits for that thread of execution to complete
thread.Join();
return 0;
}