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.

For example here is a complete, but trivial, multi-threaded application that does not need to subclass the Thread class.

    #include "ot/base/SystemMonitor.h"
    #include "ot/base/Thread.h"
    #include "ot/io/Console.h"

    using namespace ot;
    using namespace ot::io;

    class HelloSayer : public Runnable {
    public:
        virtual void run() {
            Console::Out()->println(OT_T("Hello World!"));
        }
    };

    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=, 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-2003 ElCel Technology   Trademark Acknowledgements