PTalarms

Written by Kevin L. Ellis

Download current release (version 0.1)


            PTalarms allow you to setup multiple SIGALRM signals in a pthreaded program.  I found that I wanted to have multiple alarms in my threaded program, but there was only the one alarm signal.  I wrote the library to allow my program to have multiple alarm signals (as many as there are free real-time signals).  Currently the program only works on Linux because of it's implementation of pthread (i.e. each thread is a separate process).  

            The library works like so.  Your main application calls PTinit(), this starts a background process, PTserver , that your main application connects to via a pipe.  The threads of the main application then setup signal handlers to receive the alarm by calling PTsignal(), which is called just like signal().  The threads then setup their alarm by calling PTalarm(), again it's called just like the alarm() function.  These are the only three functions needed to use the library.  The PTserver process handles the actual sending of the signal to the thread.  PTserver keeps track of the process id, signal number, and the alarm time for each thread.  It then sets up a SIGALRM signal handler and calls alarm() for the time to the first pthread alarm.  In the signal handler it determines which thread should receive the alarm signal and sends that thread (via it's process id) a signal using the kill() function.  It then resets it's alarm for the next thread's alarm that will occur.

            To use the library just unzip the file and type make.  This will make the library, PTserver, and a test program.  You can run the test program to make sure it's all working ok, but you must first copy PTserver to /usr/local/bin or similar location.  It needs to be in the path so that the library can find it.  

            Once it's working ok just type  make install ,  this will copy the library to /usr/local/library, put the include file in /usr/local/include, and copy PTserver to /usr/local/bin.  For your own programs all you need to do is include the header file and library when compiling and call PTalarms_init() before using PTsignal() and PTalarm().  Take a look at the test program to see how to use the library.