Spinning Topp Logo BlackTopp Studios
inc
Public Types | Public Member Functions | Static Public Member Functions | List of all members
Mezzanine::Threading::Thread Class Reference

A small wrapper around the system thread. More...

#include <thread.h>

Public Types

typedef pthread_t native_handle_type
 The native handle type, made available with requiring specific knowledge of whether it is a posix or win32 handle.
 

Public Member Functions

 Thread ()
 Default constructor. More...
 
 Thread (void(*aFunction)(void *))
 Thread starting constructor with no parameters. More...
 
 Thread (void(*aFunction)(void *), void *aArg)
 Thread starting constructor. More...
 
 ~Thread ()
 Destructor. More...
 
void detach ()
 Detach from the thread. More...
 
ThreadId get_id () const
 Return the thread ID of a thread object. More...
 
void join ()
 Wait for the thread to finish (join execution flows). More...
 
bool joinable () const
 Check if the thread is joinable. More...
 
native_handle_type native_handle ()
 Get the native handle for this thread. More...
 

Static Public Member Functions

static unsigned hardware_concurrency ()
 Determine the number of threads which can possibly execute concurrently. More...
 

Detailed Description

A small wrapper around the system thread.

In general game code should not be creating this if they are using the DAG Frame Scheduler, as it tries to maintain control over the threads created by a game. This tries to keep the names the same as the standard thread, and might at some point be replace by some template machinery that wraps the minor difference that currently exist.

Definition at line 94 of file thread.h.

Constructor & Destructor Documentation

Mezzanine::Threading::Thread::Thread ( )
inline

Default constructor.

Construct a thread object without an associated thread of execution (i.e. non-joinable).

Definition at line 112 of file thread.h.

Mezzanine::Threading::Thread::Thread ( void(*)(void *)  aFunction)
explicit

Thread starting constructor with no parameters.

Note
May work in templates that do not attempt to pass values to threads, but not standard conformant.
Parameters
[in]aFunctionA function pointer to a function of type:
void fun(void * arg)
Mezzanine::Threading::Thread::Thread ( void(*)(void *)  aFunction,
void *  aArg 
)

Thread starting constructor.

Construct a thread object with a new thread of execution.

Parameters
[in]aFunctionA function pointer to a function of type:
void fun(void * arg)
[in]aArgArgument to the thread function.
Note
This constructor is not fully compatible with the standard C++ thread class. It is more similar to the pthread_create() (POSIX) and CreateThread() (Windows) functions.
Mezzanine::Threading::Thread::~Thread ( )

Destructor.

Note
If the thread is joinable upon destruction, std::terminate() will be called, which terminates the process. It is always wise to do join() before deleting a thread object.

Member Function Documentation

void Mezzanine::Threading::Thread::detach ( )

Detach from the thread.

After calling detach(), the thread object is no longer assicated with a thread of execution (i.e. it is not joinable). The thread continues execution without the calling thread blocking, and when the thread ends execution, any owned resources are released.

ThreadId Mezzanine::Threading::Thread::get_id ( ) const

Return the thread ID of a thread object.

Returns
A platform specific handle for the thread.
static unsigned Mezzanine::Threading::Thread::hardware_concurrency ( )
static

Determine the number of threads which can possibly execute concurrently.

This function is useful for determining the optimal number of threads to use for a task.

Returns
The number of hardware thread contexts in the system.
Note
If this value is not defined, the function returns zero (0).
void Mezzanine::Threading::Thread::join ( )

Wait for the thread to finish (join execution flows).

After calling join(), the thread object is no longer associated with a thread of execution (i.e. it is not joinable, and you may not join with it nor detach from it).

bool Mezzanine::Threading::Thread::joinable ( ) const

Check if the thread is joinable.

A thread object is joinable if it has an associated thread of execution.

Returns
A bool, false if the thread has been detached, joined or otherwise made unjoinable by exceptional circumstances, true otherwise.
native_handle_type Mezzanine::Threading::Thread::native_handle ( )
inline

Get the native handle for this thread.

Note
Under Windows, this is a HANDLE, and under POSIX systems, this is a pthread_t.
Returns
The native handle for the thread in case it is desired to use it with OS APIs.

Definition at line 165 of file thread.h.


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