This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

1.5.10: Problem with SIGEV_THREAD


I am having a problem with timer notifications using SIGEV_THREAD. I adapted 
the sigev_thread.c program from 
http://homepage.mac.com/dbutenhof/Threads/source.html to illustrate problem.

basically my application has a main loop which reads commands from the keyboard 
and meantime in the background a timer goes off to do various timer related 
stuff. However, my main thread seems to hang after pressing return several 
times, even if the timer thread does nothing but return. It appears that when 
the timer goes off it interferes with the main thread.

So, is what I am doing valid, and if so does this represent a problem?

I am using CYGWIN_NT-5.1 on Windows XP,
gcc version 3.3.1 (cygming special)

Cheers

The code looks like this:
--------------------------
/*
 * from sigev_thread.c
 */
#include <stdio.h>
#include <pthread.h>
#include <sys/signal.h>
#include <sys/time.h>

timer_t             timer_id;
int                 counter = 0;

void
timer_thread (union sigval sig)
{
    int status;

    return;

    printf ("Timer %d\n", counter);
}

main()
{
    int     status;
    struct itimerspec ts;
    struct sigevent se;
    char            cmd [1024];
    char            *pcmd;

    /*
     * Set the sigevent structure to cause the signal to be
     * delivered by creating a new thread.
     */
    se.sigev_notify = SIGEV_THREAD;
    se.sigev_value.sival_ptr = &timer_id;
    se.sigev_notify_function = timer_thread;
    se.sigev_notify_attributes = NULL;

    /*
     * Specify a repeating timer that fires each 5 seconds.
     */
    ts.it_value.tv_sec = 1;
    ts.it_value.tv_nsec = 0;
    ts.it_interval.tv_sec = 1;
    ts.it_interval.tv_nsec = 0;

    printf ("Creating timer\n");
    status = timer_create(CLOCK_REALTIME, &se, &timer_id);
    if (status == -1)
        perror ("Create timer");

    printf ("Setting timer %x for 1-second expiration...\n", timer_id);
    status = timer_settime(timer_id, 0, &ts, 0);
    if (status == -1)
        perror ("Set timer");


    printf ("test>");
    while (1)
    {
        pcmd = gets (cmd);
        if (pcmd == NULL)
        {
            printf ("pcmd = NULL\n");
        }
        else
        {
            printf ("test>");
        }

    }
    return 0;
}



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]