Main Page Namespace List Class Hierarchy Compound List File List Namespace Members Compound Members File Members Related Pages

# wkgl::ThreadGroup Class Reference

This class allows you to perform actions on a group of threads. More...

`#include <ThreadGroup.h>`

Inheritance diagram for wkgl::ThreadGroup:

List of all members.

## Public Methods
| ThreadGroup ()
| Creates an unnamed thread group.
| ThreadGroup (char *name)
| Creates a new thread group with the given name.
| ~ThreadGroup (void)
virtual void | addThread (Thread *t)
| Adds a thread to the end of the list.
virtual BOOL | start ()
| Calls start on all the threads in the group.
virtual BOOL | stop ()
| Call stop on all the threads in the group.
virtual BOOL | suspend ()
| Calls suspend on all the threads in the group.
virtual BOOL | resume ()
| Calls resume on all the threads in the group.
virtual BOOL | waitForCompletion (DWORD mill)
| Stops the execution of the caller unitl the all the threads terminate.
virtual BOOL | waitForCompletion ()
| Stops the execution of the caller unitl the all the threads terminate.
virtual SFLAG | getState ()
| Returns the state of the group.
virtual BOOL | start (void *param)
| Executes the RUNNABLE function in a seperate thread.
virtual char * | getName ()
| Returns the name of the thread.
## Static Public Methods
void | sleep (ULONG mill)
| Causes the calling thread to stop execution for the given time.
Thread * | getCurrentThread ()
| Returns the thread of the caller.
void | wait (DWORD mill)
| Causes the calling thread to stop executing until it is notifyed.
void | wait ()
| Causes the calling thread to stop executing until it is notifyed.
void | notify ()
| Notify a single waiting thread.
void | notifyAll ()
| Notifies all waiting threads.
void | yield ()
| Attempts to yeild the calling threads time slice to the next thread.
## Protected Attributes
std::vector< Thread * > | threads
| A list of all the threads in the group.
RUNNABLE | r
| The function to run.
SFLAG | state
| The current state of the thread.
DWORD | thread_id
| The windows id of the thread.
HANDLE | thandle
| The windows handle to the thread.
char * | name
| The name of this thread.
void * | param
| The parameter to pass to r;.
## Static Protected Attributes
HANDLE | notify_event
| This event is used in the wait/notify/notifyAll scheme.
UINT | nwaiting = 0
| Counts the number of waiting threads.
## Friends
DWORD WINAPI | ThreadProc (LPVOID lpParam)
| Used by win32 api.

## Detailed Description

This class allows you to perform actions on a group of threads.

Author:
  Micheal Nooner.

This class is useful for synchronizing several threads. It allows you to start, stop, suspend, and resume multiple threads sequentially. Also the waitForCompletion method allows you to halt that caller's thread until all the threads in the group have completed execution.

## Constructor & Destructor Documentation

ThreadGroup::ThreadGroup | ( |  | ) |

| Creates an unnamed thread group.

ThreadGroup::ThreadGroup | ( | char * | name | ) |

  | Creates a new thread group with the given name. Parameters:
  name | The name of this group

ThreadGroup::~ThreadGroup | ( | void |  | ) |

## Member Function Documentation

void ThreadGroup::addThread | ( | Thread * | t | ) | `[virtual]`

| Adds a thread to the end of the list.

Thread * Thread::getCurrentThread | ( |  | ) | `[static, inherited]`

| Returns the thread of the caller. So, Thread::getCurrentThread() != Thread::getCurrentThread(). Returns: The callers thread.

char * Thread::getName | ( |  | ) | `[virtual, inherited]`

| Returns the name of the thread. Returns: The name of the thread, or NULL if the name is not set.

SFLAG ThreadGroup::getState | ( |  | ) | `[virtual]`

| Returns the state of the group. Returns: If all the threads are in the same state this method will return that state, otherwise it will return THREAD_UNKNOWN Reimplemented from wkgl::Thread.

void Thread::notify | ( |  | ) | `[static, inherited]`

| Notify a single waiting thread.

void Thread::notifyAll | ( |  | ) | `[static, inherited]`

| Notifies all waiting threads.

BOOL ThreadGroup::resume | ( |  | ) | `[virtual]`

| Calls resume on all the threads in the group. Returns: TRUE if all the threads have been resumed, FALSE otherwise. Reimplemented from wkgl::Thread.

void Thread::sleep | ( | ULONG | mill | ) | `[static, inherited]`

  | Causes the calling thread to stop execution for the given time. Parameters:
  mill | The amount of time in milliseconds that the thread should be suspended.

BOOL Thread::start | ( | void * | param | ) | `[virtual, inherited]`

  | Executes the RUNNABLE function in a seperate thread. Parameters:
  param | The parameter to pass to the runnable function.
Returns: TRUE if the thread was successfully started.

BOOL ThreadGroup::start | ( |  | ) | `[virtual]`

| Calls start on all the threads in the group. Returns: TRUE if all the threads started, FALSE otherwise. Reimplemented from wkgl::Thread.

BOOL ThreadGroup::stop | ( |  | ) | `[virtual]`

| Call stop on all the threads in the group. Returns: TRUE if all the threads have been terminated, FALSE otherwise. Reimplemented from wkgl::Thread.

BOOL ThreadGroup::suspend | ( |  | ) | `[virtual]`

| Calls suspend on all the threads in the group. Returns: TRUE if all the threads have been suspended, FALSE otherwise. Reimplemented from wkgl::Thread.

void Thread::wait | ( |  | ) | `[static, inherited]`

| Causes the calling thread to stop executing until it is notifyed.

void Thread::wait | ( | DWORD | mill | ) | `[static, inherited]`

  | Causes the calling thread to stop executing until it is notifyed. Parameters:
  mill | The number of milliseconds to wait.

BOOL ThreadGroup::waitForCompletion | ( |  | ) | `[virtual]`

| Stops the execution of the caller unitl the all the threads terminate. Returns: TRUE if all the threads have finished executing, FALSE if some error has occured. Reimplemented from wkgl::Thread.

BOOL ThreadGroup::waitForCompletion | ( | DWORD | mill | ) | `[virtual]`

  | Stops the execution of the caller unitl the all the threads terminate. Parameters:
  mill | The number of milliseconds the calling thread should wait for the target thread to exit.
Returns: TRUE if all the threads have finished executing, FALSE if the time has elapsed or some error has occured. Reimplemented from wkgl::Thread.

void Thread::yield | ( |  | ) | `[static, inherited]`

| Attempts to yeild the calling threads time slice to the next thread.

## Friends And Related Function Documentation

DWORD WINAPI ThreadProc | ( | LPVOID | lpParam | ) | `[friend, inherited]`

| Used by win32 api.

## Member Data Documentation

char* wkgl::Thread::name`[protected, inherited]`

| The name of this thread.

HANDLE Thread::notify_event`[static, protected, inherited]`

| Initial value:
     CreateEvent( NULL, TRUE, FALSE,
                                               "MNThreadEvent" )
This event is used in the wait/notify/notifyAll scheme.

UINT Thread::nwaiting = 0`[static, protected, inherited]`

| Counts the number of waiting threads.

void* wkgl::Thread::param`[protected, inherited]`

| The parameter to pass to r;.

RUNNABLE wkgl::Thread::r`[protected, inherited]`

| The function to run.

SFLAG wkgl::Thread::state`[protected, inherited]`

| The current state of the thread.

HANDLE wkgl::Thread::thandle`[protected, inherited]`

| The windows handle to the thread.

DWORD wkgl::Thread::thread_id`[protected, inherited]`

| The windows id of the thread.

std::vector<Thread*> wkgl::ThreadGroup::threads`[protected]`

| A list of all the threads in the group.

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

- ThreadGroup.h
- ThreadGroup.cpp