IThreadMemberFn

The IThreadMemberFn template class is derived from IThreadFn for dispatching C++ member functions to an object on a new thread. The template argument is the class of the object where the dispatched member functions are called.

The constructor for such objects requires the following:

The member functions must return void and accept no parameters.

Example

  class MyClass {
  public:
      void job()  {
          // Code to run on separate thread.
      }
  };

MyClass *myObj; myObj = new MyClass; INonGUIThread thread; thread.start( new IThreadMemberFn( *myObj, MyClass::job ) );

You can add support for other type of member functions by deriving a class from IThreadFn.

Example 2

  class Foo {
  public:
      void job(int a, double b, Foo* other) {
          // Code to run on separate thread.
      }
  };
  class IFooFn : public IThreadFn
  {
  public:
       typedef void (Foo::* func_t)(int, double, Foo*);
       FooFn(Foo& f, func_t fn, int a, double b, Foo* o)
          : foo(f), func(fn), _a(a), _b(b), _o(o) {}
       virtual void run() {
           (foo.*func)(_a, _b, _o);
       }
  private:
       Foo& foo;
       func_t func;
       int _a;
       double _b;
       Foo* _o;
  }

Foo *foo = new Foo(); INonGUIThread thread; thread.start( new IFooFn(*foo, &Foo::job, 1, 1.0, foo) );


IThreadMemberFn - Member Functions and Data by Group

Constructors & Destructor

Use these members to construct and destruct objects of this template class.


[view class]
~IThreadMemberFn
public:
virtual ~IThreadMemberFn()
Destroys the thread member function object.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


[view class]
IThreadMemberFn
public:
IThreadMemberFn(T& obj, void ( T::* mem ) ( ))
You construct objects of this class by specifying an argument of the template argument class and a pointer to a member function of the template argument class.
obj
Object of the template argument class T.
mem
Pointer to a member function of the template argument class. The member function should return a void parameter and accept no formal parameters.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


Run Function

Use these members to run the member function that was specified when an object of this class was created.


[view class]
run
public:
virtual void run()
Calls the member function that you specify when you create an object of this class.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


IThreadMemberFn - Inherited Member Functions and Data

Inherited Public Functions

IThreadFn

Inherited Public Data

Inherited Protected Functions

Inherited Protected Data