Implementing POSIX Timers on AIX - Holy Moly

This is a discussion on Implementing POSIX Timers on AIX - Holy Moly within the C Programming forums, part of the General Programming Boards category; Hello, I have a real simple program that uses the POSIX create_timer() function, which is as follows-this code sample is ...

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

    Implementing POSIX Timers on AIX - Holy Moly

    Hello,

    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:

    Code:
    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);
        perror("");
        exit(rc);
    }
    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.

    Thanks,
    dedham_ma_man

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,691
    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.

    gg

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,764
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 06:46 AM
  2. Holy moly!!!
    By caddy39 in forum C Programming
    Replies: 5
    Last Post: 07-22-2007, 03:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21