Torque2D Reference

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Public Attributes | Protected Attributes | List of all members
Thread Class Reference

`#include <thread.h>`

Inheritance diagram for Thread:

## Public Member Functions
| Thread (ThreadRunFunction func=0, void *arg=0, bool start_thread=true, bool autodelete=false)
virtual | ~Thread ()
void | start ()
void | stop ()
| Ask a thread to stop running. More...
bool | join ()
| Block until the thread stops running. More...
bool | checkForStop ()
virtual void | run (void *arg=0)
bool | isAlive ()
| Returns true if the thread is running. More...
ThreadIdent | getId ()
| Returns the platform specific thread id for this thread. More...

## Public Attributes
bool | autoDelete
| If set, the thread will delete itself once it has finished running. More...

## Protected Attributes
PlatformThreadData * | mData
bool | shouldStop

## Constructor & Destructor Documentation

Thread | ( | ThreadRunFunction | func = `0`,
|  | void * | arg = `0`,
|  | bool | start_thread = `true`,
|  | bool | autodelete = `false`
| ) |  |

Create a thread.

Parameters

  func | The starting function for the thread.
  arg | Data to be passed to func, when the thread starts.
  start_thread | Whether to start the Thread immediately.

~Thread | ( |  | ) |
| virtual

Destroy a thread. The thread MUST be allowed to exit before it is destroyed.

## Member Function Documentation

bool checkForStop | ( |  | ) |
| inline

Threads may call checkForStop() periodically to check if they've been asked to stop. As soon as checkForStop() returns true, the thread should clean up and return.

U32 getId | ( |  | ) |

Returns the platform specific thread id for this thread.

bool isAlive | ( |  | ) |

Returns true if the thread is running.

bool join | ( |  | ) |

Block until the thread stops running.

void run | ( | void * | arg = `0` | ) |
| virtual

Run the Thread's entry point function. Override this method in a subclass of Thread to create threaded code in an object oriented way, and without passing a function ptr to Thread(). Also, you can call this method directly to execute the thread's code in a non-threaded way.

Reimplemented in ExecuteThread.

void start | ( |  | ) |

Start a thread. Sets shouldStop to false and calls run() in a new thread of execution.

void stop | ( |  | ) |
| inline

Ask a thread to stop running.

## Member Data Documentation

bool autoDelete

If set, the thread will delete itself once it has finished running.

PlatformThreadData* mData
| protected

bool shouldStop
| protected

Used to signal threads need to stop. Threads set this flag to false in start()

The documentation for this class was generated from the following files:

- platform/threads/thread.h
- platformAndroid/AndroidThread.cpp
- platformEmscripten/EmscriptenThread.cpp