Loading...
Searching...
No Matches
libthreadar::thread_signal Class Reference

Class thread_signal provides the same interface as class thread but in addition relies on a signal to awake 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_signal & | operator= (const thread_signal &ref)=delete
thread_signal & | operator= (thread_signal &&ref) noexcept=default
virtual | ~thread_signal ()=default
| destructor
virtual void | set_signal_mask (const sigset_t &mask) override
| 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
thread & | operator= (const thread &ref)=delete
thread & | operator= (thread &&ref) noexcept=default
virtual | ~thread ()
| destructor
void | reset_stack_size ()
| reset the stack size to the system default value
void | set_stack_size (unsigned int val)
| set the stack size to non default value
unsigned int | get_stack_size () const
| get the current stack size value
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() and should be used instead of it
Protected Member Functions inherited from libthreadar::thread
virtual void | inherited_run ()=0
| action to be performed in the separated thread (implementation is expected in inherited classes)
void | cancellation_checkpoint () const
| available withing the inherited_run() method to eventually trigger thread cancellation

## Detailed Description

Class thread_signal provides the same interface as class thread but in addition relies on a signal to awake the tread if it was pending on a system call.

This class derives from class libthreadar::thread and is used the same. However a signal has to be reserved for the whole process for any thread to be awaken in case it would be pending on a system call. In such situation a system call returns EINTR code and your thread implementation should consider this value as usually and probably retry the system call. Though, before retrying, this let your code invoke the cancellation_checkpoint() method to check whether an thread cancellation was requested, which method will in that case throw a thread::cancel_except exception that should not be catched by the code of inherited_run() method. The signal handle associated to this signal is implemented in this class but does nothing. So if your code does not call cancellation_checkpoint() it will continue to run normally, except for the point when the thread was pending on a system call which will in that case return EINTR.

Note
  the signal used for this class 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
  your program should not define any handle for that signal, this is the class, globally, that will define it at the time the first object of an inherited class will be constructed or at the next time an object is constructed if change_default_signal() is used to change the signal to use after an object has already been created. This call has thus no effect until a new object from an inherited class is created.

## set_signal_mask()

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

override virtual

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 will ignore it

Reimplemented from libthreadar::thread.

## signaled_inherited_cancel()

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

inline protected virtual

replaces thread::inherited_cancel() and should be used instead of it

Note
  except the method name that changes, the purpose is the same as inherited_cancel(): you have the possibility to provide your own implementation of signaled_inherited_cancel() to implement an alternative method of cancelling a thread. This method will be invoked when the thread::cancel() method will be called, right before the signal is sent to the thread if it was running.

Definition at line 105 of file thread_signal.hpp.

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

- thread_signal.hpp