Thread: Implementing POSIX Timers on AIX - Holy Moly

  1. #1
    Registered User
    Join Date
    Mar 2006
    dedham, MA

    Implementing POSIX Timers on AIX - Holy Moly


    I have a real simple program that uses the POSIX create_timer() function, which is as follows-this code sample is standard and models other code samples that I've found on POSIX timer implementation:

    void callback(union sigval sigev_value) { printf("In callback()\n"); }
    void main()
        int rc;
        timer_t *timer_id;
        struct sigevent evp;
        memset((void *)&evp, 0, sizeof(evp));
        timer_id = (timer_id*)malloc(sizeof(timer_id));
        evp.sigev_notify_function = &callback;
        evp.sigev_value.sival_ptr = (void*)timer_id;
        errno = 0;
        if (rc = timer_create(CLOCK_REALTIME, &evp, timer_id)) {
        printf("timer_create() Rtn rc %d error %d\n", rc, errno);
    But when I run it, I get the following output:

    % timer
    timer_create() Rtn rc -1 Error 0
    Invalid Argument

    What Invalid Argument? The arguments passed into timer_create are fine. It compiles OK. What could be the problem. Any ideas at all would be helpful.


  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Try passing in NULL for the evp and see if you still get an error. If you don't, then I'd guess that some additional members of evp need fill'n out.

    2.4.2 Realtime Signal Generation and Delivery

    I would try setting sigev_notify to SIGEV_THREAD.


  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > void main()
    main returns int, see the FAQ.

    > memset((void *)&evp, 0, sizeof(evp));
    This cast is pointless, since C casts to void* automatically and silently anyway.

    > timer_id = (timer_id*)malloc(sizeof(timer_id));
    There's no need to cast the result of malloc in C, see the FAQ.

    > It compiles OK.
    Everyone says that, but it doesn't mean anything. There are infinitely more programs which compile compared to those which actually do what you want.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. POSIX timers in c++
    By suo in forum C++ Programming
    Replies: 4
    Last Post: 07-01-2009, 05:46 AM
  2. Holy moly!!!
    By caddy39 in forum C Programming
    Replies: 5
    Last Post: 07-22-2007, 02:21 PM