Cross-Platform C++

ot
class Runnable  (abstract)

#include "ot/base/Runnable.h"

ot::ManagedObject ot::Thread Abstract 'interface' class which should be implemented by any class whose instances are intended to be executed by a Thread. The derived class must implement the pure virtual run() method. By deriving from Runnable, a class is able to get the benefit of executing in a separate thread without having to derive from the Thread class itself. This can create a cleaner separation of responsibility.

To execute a Runnable class's run() method, create a new Thread instance passing a pointer to the Runnable object as a parameter.

Here's a complete, but trivial, example multi-threaded application that doesn't subclass the Thread class - it derives from Runnable instead.

    #include "ot/base/SystemMonitor.h"
    #include "ot/base/Thread.h"
    #include <iostream>

    using namespace std;
    using namespace ot;

    class HelloSayer : public Runnable
    {
    public:
        virtual void run()
        {
            cout << "Hello World!" << endl;
        }
    };

    int main()
    {
        SystemMonitor monitor; // ensures correct termination processing
        RefPtr<Thread> rpThread = new Thread(new HelloSayer);
        rpThread->start();
        return 0;
    }




Method Summary
 virtual void run()=0
         Called by a Thread's start-up function when it has been initiated.

Methods inherited from class ot::ManagedObject
addRef(), getRefCount(), onFinalRelease(), operator=(const ManagedObject&), release()

Method Detail

run

virtual void run()=0
Called by a Thread's start-up function when it has been initiated.



Cross-Platform C++

Found a bug or missing feature? Please email us at support@elcel.com

Copyright © 2000-2005 ElCel Technology   Trademark Acknowledgements