Creating a thread

One thread can create a sibling thread within its own task by instantiating a subclass of TThreadProgram to encapsulate the thread's program and schedule, and using it to create a TThreadHandle object:

      TSomeThreadProgram* aProgramPtr = new TSomeThreadProgram(constructor arguments);
      TThreadHandle* aThread = new TThreadHandle(aProgramPtr);
In this example, the new thread adopts the thread program; no copy of the thread program is made, and the new thread deletes it when it finishes execution. Alternatively, you could use a different TThreadHandle constructor:

      TSomeThreadProgram aProgram(constructor arguments);
      TThreadHandle* aThread = new TThreadHandle(aProgram);
In this case, the new thread runs its own copy of the thread program.

If you derive your own subclass of TThreadProgram, you must override the Run() member function, the entry point for the thread's program. Optionally, you can override the Prepare() member function to perform some setup or initialization before Run() is called.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker