join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::Thread Class Reference

thread class. More...

#include <thread.hpp>

Public Member Functions

 Thread () noexcept=default
 default constructor.
 
template<class Function , class... Args>
 Thread (Function &&func, Args &&... args)
 creates a new thread object associated with a thread of execution.
 
template<class Function , class... Args>
 Thread (int core, int prio, Function &&func, Args &&... args)
 creates a new thread object associated with a thread of execution.
 
 Thread (const Thread &other)=delete
 copy constructor.
 
Threadoperator= (const Thread &other)=delete
 copy assignment.
 
 Thread (Thread &&other) noexcept
 move constructor.
 
Threadoperator= (Thread &&other) noexcept
 move assignment.
 
 ~Thread ()
 destroys the thread object.
 
int affinity (int core)
 set thread affinity.
 
int affinity () const noexcept
 get current thread affinity.
 
int priority (int prio)
 set thread priority.
 
int priority () const noexcept
 get current thread priority.
 
bool joinable () const noexcept
 check if thread is joinable.
 
bool running () const noexcept
 check if the thread is running.
 
void join () noexcept
 block the current thread until the running thread finishes its execution.
 
bool tryJoin () noexcept
 performs a nonblocking join on the running thread.
 
void cancel () noexcept
 cancel the running thread if any.
 
void swap (Thread &other) noexcept
 swap underlying handles of two thread objects.
 
pthread_t handle () const noexcept
 get the handle of the thread of execution. @retunr thread of execution handle.
 

Static Public Member Functions

static int affinity (pthread_t handle, int core)
 set thread affinity.
 
static int priority (pthread_t handle, int prio)
 set thread priority.
 

Detailed Description

thread class.

Constructor & Destructor Documentation

◆ Thread() [1/5]

join::Thread::Thread ( )
defaultnoexcept

default constructor.

◆ Thread() [2/5]

template<class Function , class... Args>
join::Thread::Thread ( Function && func,
Args &&... args )
inlineexplicit

creates a new thread object associated with a thread of execution.

Parameters
funccallable object to execute in the new thread.
args...arguments to pass to the new function.

◆ Thread() [3/5]

template<class Function , class... Args>
join::Thread::Thread ( int core,
int prio,
Function && func,
Args &&... args )
inlineexplicit

creates a new thread object associated with a thread of execution.

Parameters
corethread core affinity (-1 no pinning).
priothread priority (0 = SCHED_OTHER, 1-99 = SCHED_FIFO).
funccallable object to execute in the new thread.
args...arguments to pass to the new function.

◆ Thread() [4/5]

join::Thread::Thread ( const Thread & other)
delete

copy constructor.

Parameters
otherother object to copy.

◆ Thread() [5/5]

Thread::Thread ( Thread && other)
noexcept

move constructor.

Parameters
otherother object to move.

◆ ~Thread()

Thread::~Thread ( )

destroys the thread object.

Member Function Documentation

◆ affinity() [1/3]

int Thread::affinity ( ) const
noexcept

get current thread affinity.

Returns
affinity or -1 if not pinned.

◆ affinity() [2/3]

int Thread::affinity ( int core)

set thread affinity.

Parameters
corethread core affinity (-1 to disable pinning).
Returns
0 on success, -1 on failure.

◆ affinity() [3/3]

int Thread::affinity ( pthread_t handle,
int core )
static

set thread affinity.

Parameters
handlethread handle.
corethread core affinity (-1 to disable pinning).
Returns
0 on success, -1 on failure.

◆ cancel()

void Thread::cancel ( )
noexcept

cancel the running thread if any.

◆ handle()

pthread_t Thread::handle ( ) const
noexcept

get the handle of the thread of execution. @retunr thread of execution handle.

◆ join()

void Thread::join ( )
noexcept

block the current thread until the running thread finishes its execution.

◆ joinable()

bool Thread::joinable ( ) const
noexcept

check if thread is joinable.

Returns
true if joinable.

◆ operator=() [1/2]

Thread & join::Thread::operator= ( const Thread & other)
delete

copy assignment.

Parameters
otherother object to copy.
Returns
a reference to the current object.

◆ operator=() [2/2]

Thread & Thread::operator= ( Thread && other)
noexcept

move assignment.

Parameters
otherother object to move.
Returns
a reference to the current object.

◆ priority() [1/3]

int Thread::priority ( ) const
noexcept

get current thread priority.

Returns
priority.

◆ priority() [2/3]

int Thread::priority ( int prio)

set thread priority.

Parameters
priothread priority (0 = SCHED_OTHER, 1-99 = SCHED_FIFO).
Returns
0 on success, -1 on failure.

◆ priority() [3/3]

int Thread::priority ( pthread_t handle,
int prio )
static

set thread priority.

Parameters
handlethread handle.
priothread priority (0 = SCHED_OTHER, 1-99 = SCHED_FIFO).
Returns
0 on success, -1 on failure.

◆ running()

bool Thread::running ( ) const
noexcept

check if the thread is running.

Returns
true if running, false otherwise.

◆ swap()

void Thread::swap ( Thread & other)
noexcept

swap underlying handles of two thread objects.

Parameters
otherthe thread to swap with.

◆ tryJoin()

bool Thread::tryJoin ( )
noexcept

performs a nonblocking join on the running thread.

Returns
true if thread was joined, false if running thread didn't finished its execution.

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