Open Lighting Architecture 0.10.9
Loading...
Searching...
No Matches
ola::thread::SignalThread Class Reference

Detailed Description

Signals and threads don't play nicely together. Consider the following:

  • thread1, acquires mutex M
  • signal triggers
  • thread1 runs the signal handler
  • signal handler attempts to acquire mutex M
  • deadlock...

The recommended way to deal with this is to run a separate thread, whose sole purpose is to wait for signals. See section 12.8 of APUE.

To avoid this we do the following:

  • mask all signals that we define custom handlers for
  • spawn a thread which uses sigwait() to capture signals
Inheritance diagram for ola::thread::SignalThread:
ola::thread::Thread

Public Types

typedef ola::Callback0< void > SignalHandler
 

Public Member Functions

bool InstallSignalHandler (int signal, SignalHandler *handler)
 Install a signal handler for the given signal.
 
- Public Member Functions inherited from ola::thread::Thread
 Thread (const Options &options=Options())
 Create a new thread with the specified thread options.
 
virtual ~Thread ()
 Destructor.
 
virtual bool Start ()
 Start the thread and wait for the thread to be running.
 
virtual bool FastStart ()
 Start the thread and return immediately.
 
virtual bool Join (void *ptr=NULL)
 Join this thread.
 
bool IsRunning ()
 Check if the thread is running.
 
ThreadId Id () const
 Return the thread id.
 
std::string Name () const
 Return the thread name.
 

Protected Member Functions

void * Run ()
 Entry point into the thread.
 
- Protected Member Functions inherited from ola::thread::Thread

Additional Inherited Members

- Static Public Member Functions inherited from ola::thread::Thread
static ThreadId Self ()
 Returns the current thread's id.
 

Member Function Documentation

◆ InstallSignalHandler()

bool ola::thread::SignalThread::InstallSignalHandler ( int signal,
SignalHandler * handler )

Install a signal handler for the given signal.

This can't be called once the thread has stared.

◆ Run()

void * ola::thread::SignalThread::Run ( )
protectedvirtual

Entry point into the thread.

Implements ola::thread::Thread.


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