Libthreadar 1.5.0
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
libthreadar::thread_signal Class Reference

Class thread_signal provide the same interface as class thread but relies on a signal to wakeup the tread if it was pending on a system call. More...

#include <thread_signal.hpp>

Inherits libthreadar::thread.

Public Member Functions

 thread_signal ()
 constructor
 
 thread_signal (const thread_signal &ref)=delete
 copy constructor and assignment operator are disabled from libhtreadar::thread
 
 thread_signal (thread_signal &&ref) noexcept=default
 
thread_signaloperator= (const thread_signal &ref)=delete
 
thread_signaloperator= (thread_signal &&ref) noexcept=default
 
virtual ~thread_signal ()=default
 destructor
 
void set_signal_mask (const sigset_t &mask)
 set signal mask for this object's when the thread_signal will be run
 
- Public Member Functions inherited from libthreadar::thread
 thread ()
 constructor
 
 thread (const thread &ref)=delete
 copy constructor and assignment operator are disabled
 
 thread (thread &&ref) noexcept=default
 
threadoperator= (const thread &ref)=delete
 
threadoperator= (thread &&ref) noexcept=default
 
virtual ~thread ()
 destructor
 
void set_signal_mask (const sigset_t &mask)
 set signal mask for this object's when the thread will be run
 
void run ()
 launch the current object routing in a separated thread
 
bool is_running () const
 checks whether a separated thread is running the inherited_run() method of this object
 
bool is_running (pthread_t &id) const
 checks whether the object is running in a separated thread
 
void join () const
 the caller will be suspended until the current object's thread ends
 
void kill () const
 
void cancel ()
 the caller send a cancellation request to this object's running thread if any
 

Static Public Member Functions

static void change_default_signal (int sig)
 change the signal used to awake threads
 

Protected Member Functions

virtual void signaled_inherited_cancel ()
 replaces thread::inherited_cancel()
 
- Protected Member Functions inherited from libthreadar::thread
virtual void inherited_run ()=0
 action to be performed in the separated thread
 
void cancellation_checkpoint () const
 available withing the inherited_run() method to eventually trigger thread cancellation
 

Detailed Description

Class thread_signal provide the same interface as class thread but relies on a signal to wakeup the tread if it was pending on a system call.

this class derives from class libthread::thread and is used the same. However a signal has to be reserved for the whole process and thus for all threads to awake thread in case it would be pending on a system call. In such situation system call return EINTR code and your thread should consider this value as usually and probably retry the system call. Though, this let your code invoke the cancellation_checkpoint() method that will and only this will trigger the end of the thread by throwing an thread::cancel_except exception that should not be catched by the code of inherited_run() method. The signal handle associated to this signal does nothing, so if your code does not call cancellation_checkpoint() it will continue to run transparently (except for system call that return EINTR in that context).

Note
the signal used can be set using the static method change_default_signal()

Definition at line 60 of file thread_signal.hpp.

Member Function Documentation

◆ change_default_signal()

static void libthreadar::thread_signal::change_default_signal ( int  sig)
static

change the signal used to awake threads

Note
by default the signal used to awake a thread is SIGUSR2

◆ set_signal_mask()

void libthreadar::thread_signal::set_signal_mask ( const sigset_t &  mask)

set signal mask for this object's when the thread_signal will be run

Note
see sigsetops(3) for details on manipulating signal sets
this is a modified version of thread::set_signal_mask() that removes from the sigset_t the signal used to awake threads so no thread_signal

◆ signaled_inherited_cancel()

virtual void libthreadar::thread_signal::signaled_inherited_cancel ( )
inlineprotectedvirtual

replaces thread::inherited_cancel()

Note
except the method name that changes, the purpose is the same

Definition at line 94 of file thread_signal.hpp.


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