delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/06/30/13:20:27

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
To: cygwin AT cygwin DOT com
From: Bob Cousins <bobcousins34 AT hotmail DOT com>
Subject: 1.5.10: Problem with =?utf-8?b?U0lHRVZfVEhSRUFE?=
Date: Wed, 30 Jun 2004 17:18:28 +0000 (UTC)
Lines: 93
Message-ID: <loom.20040630T190035-117@post.gmane.org>
Mime-Version: 1.0
X-Complaints-To: usenet AT sea DOT gmane DOT org
X-Gmane-NNTP-Posting-Host: main.gmane.org
User-Agent: Loom/3.14 (http://gmane.org/)
X-Loom-IP: 62.254.217.180 (Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1))

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019