LightWrap++
AC++wrapperfortheLightWave3DSDK
lwpp::ThreadGroup Class Reference

#include <threads.h>

+ Inheritance diagram for lwpp::ThreadGroup:
+ Collaboration diagram for lwpp::ThreadGroup:

List of all members.

Public Member Functions

 ThreadGroup (int _count)
 ~ThreadGroup ()
 Destroys the thread group created by createGroup().
void abort ()
 Signals to all active threads in the group that it is time to stop.
LWMTThreadID addThread (LWMTThreadFunc func, int size, void *arg)
 Adds thread functions to the thread group.
LWMTThreadID addThread (Thread *func)
virtual bool available () const
 Check if the global is available.
bool begin ()
 Causes the threads managed by the group to leave their suspended state, and begin execution (simultaneously, non-blocking).
virtual LWMTUtilFuncs * getGlobal ()
 Get the pointer to the global.
int getThreadCount ()
 Returns the number of threads the specified group is managing.
LWMTThreadID getThreadID (int in_index)
 Given a thread index (thrdndx), this function will return that thread's identifier.
bool isAborted ()
 This query function tests to see if the threads in the group were aborted for some reason.
bool isDone ()
 This query function tests to see if all the threads in the group have terminated.
void kill ()
 This function summarily terminates all active threads in the group.
int lockMutex (int mutexID)
 Attempts to gain a lock on the group's indicated mutex.
LWMTUtilFuncs * operator-> ()
 Get the pointer to the global.
bool run ()
 Causes the threads managed by the group to leave their suspended state, and begin execution (simultaneously, blocking).
void sync ()
 Once started by groupBegin, this function will block the calling process until all active threads in the group complete.
int threadResult (int in_index)
 The result (i.e, the return code) of an individual thread can be queried using this function.
int unlockMutex (int mutexID)
 Releases a lock on a group's mutex.

Protected Member Functions

bool _acquireGlobal ()

Static Protected Attributes

static LWMTUtilFuncs * globPtr
 Pointer to the global functions.

Detailed Description

Cross-platform threading support is provided by the functions in the following sections. Threads are powerful tools for the developer that allow simultaneous paths of execution to exist within the same application. On single-core, single-processor systems, threads typically execute synchronously. However, on multi-processor (or multi-core) systems, threads will often execute in true parallel, allowing the application to be more responsive than would be allowed by a single-path execution model.

Note:
These functions only provide the mechanism for multi-threading. What you do within the threads you create is entirely your concern. The responsibility lies with you, the developer, to ensure that the functions you call from within your thread that lead to paths outside your thread are safe to be called in that fashion (i.e., "thread-safe"). The practice of calling LightWaveŽ Plug-In API functions from within a thread is not officially supported. Please be aware that such a practice is undertaken by you at your own risk.

Constructor & Destructor Documentation

lwpp::ThreadGroup::ThreadGroup ( int  _count)
inline

Threads in LightWaveŽ are contained in, and managed by, "thread groups". Each thread group can contain any number of threads, and must be created with the number of threads to be managed provided in count.

lwpp::ThreadGroup::~ThreadGroup ( )
inline

Destroys the thread group created by createGroup().

If active threads exist in the group when it is destroyed, they will be forcibly stopped.


Member Function Documentation

bool lwpp::GlobalBase< LWMTUtilFuncs >::_acquireGlobal ( )
inlineprotectedinherited
void lwpp::ThreadGroup::abort ( )
inline

Signals to all active threads in the group that it is time to stop.

This is a cooperative function – the threads must periodically check for the abort condition, and then terminate.

LWMTThreadID lwpp::ThreadGroup::addThread ( LWMTThreadFunc  func,
int  size,
void *  arg 
)
inline

Adds thread functions to the thread group.

The function to be added must match the LWMTThreadFunc signature. Each thread must accept a single void * argument, which is a pointer to the thread argument data argvalue.

This thread argument can be specified by the argvalue parameter. If argsize is greater than zero (i.e., it specifies the size of the data pointed to by argvalue), then the value pointed to by argvalue will be passed to the thread fuction by value (a copy is made). On the other hand, if argsize is zero, then argvalue will be passed to the thread function by reference (i.e., the actual pointer will be provided).

As threads are added to the group, they are maintained in a suspended state. Threads do not start until the group launches them with one of the execution functions (see below).

LWMTThreadID lwpp::ThreadGroup::addThread ( Thread func)
inline
virtual bool lwpp::GlobalBase< LWMTUtilFuncs >::available ( ) const
inlinevirtualinherited

Check if the global is available.

bool lwpp::ThreadGroup::begin ( )
inline

Causes the threads managed by the group to leave their suspended state, and begin execution (simultaneously, non-blocking).

This function does not block, returning after all threads are started (or an error occurs).

Returns:
true upon success and false if there was an error.
virtual LWMTUtilFuncs * lwpp::GlobalBase< LWMTUtilFuncs >::getGlobal ( )
inlinevirtualinherited

Get the pointer to the global.

int lwpp::ThreadGroup::getThreadCount ( )
inline

Returns the number of threads the specified group is managing.

LWMTThreadID lwpp::ThreadGroup::getThreadID ( int  in_index)
inline

Given a thread index (thrdndx), this function will return that thread's identifier.

bool lwpp::ThreadGroup::isAborted ( )
inline

This query function tests to see if the threads in the group were aborted for some reason.

bool lwpp::ThreadGroup::isDone ( )
inline

This query function tests to see if all the threads in the group have terminated.

void lwpp::ThreadGroup::kill ( )
inline

This function summarily terminates all active threads in the group.

Threads are not afforded the opportunity for graceful termination.

int lwpp::ThreadGroup::lockMutex ( int  mutexID)
inline

Attempts to gain a lock on the group's indicated mutex.

Groups contain ten mutexes, numbered from 0 to 9. The call will block until the mutex is locked.

LWMTUtilFuncs * lwpp::GlobalBase< LWMTUtilFuncs >::operator-> ( )
inlineinherited

Get the pointer to the global.

bool lwpp::ThreadGroup::run ( )
inline

Causes the threads managed by the group to leave their suspended state, and begin execution (simultaneously, blocking).

This function blocks until all threads complete their processing (i.e., terminate).

Returns:
true upon success and false if there was an error.
void lwpp::ThreadGroup::sync ( )
inline

Once started by groupBegin, this function will block the calling process until all active threads in the group complete.

Calling groupBegin followed immediately by groupSync is therefore functionally equivalent to a single call to groupRun.

int lwpp::ThreadGroup::threadResult ( int  in_index)
inline

The result (i.e, the return code) of an individual thread can be queried using this function.

int lwpp::ThreadGroup::unlockMutex ( int  mutexID)
inline

Releases a lock on a group's mutex.


Member Data Documentation

LWMTUtilFuncs * lwpp::GlobalBase< LWMTUtilFuncs >::globPtr
staticprotectedinherited

Pointer to the global functions.


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