How to fill in the struct sigevent

Let's take a quick look at how you fill in the struct sigevent structure.

Regardless of the notification scheme you choose, you'll need to fill in a struct sigevent structure:

struct sigevent {
    int                 sigev_notify;

    union {
        int             sigev_signo;
        int             sigev_coid;
        int             sigev_id;
        void          (*sigev_notify_function) (union sigval);
    };

    union sigval        sigev_value;

    union {
        struct {
            short       sigev_code;
            short       sigev_priority;
        };
        pthread_attr_t *sigev_notify_attributes;
    };
};
Note: Note that the above definition uses anonymous unions and structures. Careful examination of the header file will show you how this trick is implemented on compilers that don't support these features. Basically, there's a #define that uses a named union and structure to make it look like it's an anonymous union. Check out <sys/siginfo.h> for details.

The first field you have to fill in is the sigev_notify member. This determines the notification type you've selected:

SIGEV_PULSE
A pulse will be sent.
SIGEV_SIGNAL, SIGEV_SIGNAL_CODE, or SIGEV_SIGNAL_THREAD
A signal will be sent.
SIGEV_UNBLOCK
Not used in this case; used with kernel timeouts (see "Kernel timeouts" below).
SIGEV_INTR
Not used in this case; used with interrupts (see the Interrupts chapter).
SIGEV_THREAD
Creates a thread.

Since we're going to be using the struct sigevent with timers, we're concerned only with the SIGEV_PULSE, SIGEV_SIGNAL* and SIGEV_THREAD values for sigev_notify; we'll see the other types as mentioned in the list above.