Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Nz::Thread Class Reference

Core class that represents a thread. More...

Inherits Id.

Public Member Functions

template<typename F >
 Thread (F function)
 Constructs a Thread object with a function. More...
 
template<typename F , typename... Args>
 Thread (F function, Args &&... args)
 Constructs a Thread object with a function and its parameters. More...
 
template<typename C >
 Thread (void(C::*function)(), C *object)
 Constructs a Thread object with a member function and its object. More...
 
 Thread (const Thread &)=delete
 
 Thread (Thread &&other) noexcept=default
 
 ~Thread ()
 Waits that the thread ends and then destroys this.
 
void Detach ()
 Detaches the thread.
 
Id GetId () const
 Gets the id of the thread. More...
 
bool IsJoinable () const
 Checks whether the thread can be joined. More...
 
void Join ()
 Waits that the thread ends. More...
 
void SetName (const String &name)
 Changes the debugging name associated to a thread. More...
 
Threadoperator= (const Thread &)=delete
 
Threadoperator= (Thread &&thread) noexcept=default
 

Static Public Member Functions

static unsigned int HardwareConcurrency ()
 Gets the number of simulatenous threads that can run on the same cpu. More...
 
static void SetCurrentThreadName (const String &name)
 Changes the debugging name associated to the calling thread. More...
 
static void Sleep (UInt32 milliseconds)
 Makes sleep this thread. More...
 

Friends

NAZARA_CORE_API friend bool operator== (const Id &lhs, const Id &rhs)
 
NAZARA_CORE_API friend bool operator!= (const Id &lhs, const Id &rhs)
 
NAZARA_CORE_API friend bool operator< (const Id &lhs, const Id &rhs)
 
NAZARA_CORE_API friend bool operator<= (const Id &lhs, const Id &rhs)
 
NAZARA_CORE_API friend bool operator> (const Id &lhs, const Id &rhs)
 
NAZARA_CORE_API friend bool operator>= (const Id &lhs, const Id &rhs)
 
NAZARA_CORE_API friend std::ostream & operator<< (std::ostream &o, const Id &id)
 

Detailed Description

Core class that represents a thread.

Constructor & Destructor Documentation

◆ Thread() [1/3]

template<typename F >
Nz::Thread::Thread ( function)

Constructs a Thread object with a function.

Parameters
functionTask the thread will execute in parallel

◆ Thread() [2/3]

template<typename F , typename... Args>
Nz::Thread::Thread ( function,
Args &&...  args 
)

Constructs a Thread object with a function and its parameters.

Parameters
functionTask the thread will execute in parallel
argsArguments of the function

◆ Thread() [3/3]

template<typename C >
Nz::Thread::Thread ( void(C::*)()  function,
C *  object 
)

Constructs a Thread object with a member function and its object.

Parameters
functionTask the thread will execute in parallel
objectObject on which the method will be called

Member Function Documentation

◆ GetId()

Thread::Id Nz::Thread::GetId ( ) const

Gets the id of the thread.

Returns
The identifiant of the thread (PID)

◆ HardwareConcurrency()

unsigned int Nz::Thread::HardwareConcurrency ( )
static

Gets the number of simulatenous threads that can run on the same cpu.

Returns
The number of simulatenous threads

◆ IsJoinable()

bool Nz::Thread::IsJoinable ( ) const

Checks whether the thread can be joined.

Returns
true if well formed and not detached

◆ Join()

void Nz::Thread::Join ( )

Waits that the thread ends.

Remarks
Produce a NazaraError if no functor was assigned and NAZARA_CORE_SAFE is defined

◆ SetCurrentThreadName()

void Nz::Thread::SetCurrentThreadName ( const String name)
static

Changes the debugging name associated to the calling thread.

Changes the debugging name associated with the calling thread, and may helps with debugging tools.

Parameters
nameThe new name associated with this thread
Remarks
Due to system limitations, thread name cannot exceed 15 characters (excluding null-terminator)
See also
SetName

◆ SetName()

void Nz::Thread::SetName ( const String name)

Changes the debugging name associated to a thread.

Changes the debugging name associated with a particular thread, and may helps with debugging tools.

Parameters
nameThe new name of the thread
Remarks
Due to system limitations, thread name cannot exceed 15 characters (excluding null-terminator)
See also
SetCurrentThreadName

◆ Sleep()

void Nz::Thread::Sleep ( UInt32  milliseconds)
static

Makes sleep this thread.

Parameters
millisecondsThe number of milliseconds to sleep

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