Problem with select, stdout, SIGALRM

I don't know if this is the best forum for it, please point me to a good unix dev forum otherwise.

FUrthermore it is probably, but not definitely, an issue with CYGWIN. The thing is I made the cygwin mailing list my first point of call but after getting a welcome message for joining, all of my attempted emails bounced! Presumably an overzealous spam filter, but i've never found it so hard to register a bug report about something... since it may also be a general fault common to any unix-like environment, here I am.

I have a single threaded app that loops, polls network activity with a 'select' function and interrupts the flow of the loop when a SIGALRM signal is ran, the handler of which sets a variable that the loop responds to.

While this app more-or-less ran fine in its native linux environment, when trying to run it at home in cygwin a problem occurs. Basically, between about 2-100 seconds of starting the process (on average), the alarm signal never runs as scheduled and never runs again, except for one more time when I hit CTRL+C (which I know by inserting debugging output into the signal handler). The erratic nature of when exactly the problem manifests I have a suspicion is merely how offset from a given second my starting the process is... though I could be mistaken.

The funny thing is the app happily continues looping and calling the 'select' function, it just never gets interrupted by an alarm signal. The select function handles cases of EINTR where it was interrupted by an alarm, btw (sockets are nonblocking and timeout is 2 seconds).

Now here's the REALLY weird bit. IF I insert a printf (with newline terminated string) after the select function, _the problem never occurs_.

Doesn't work if I put it before the select function, only after.

I haven't included any io streams into the fd_sets passed to the select function, in case you were wondering. They are zeroed and then only receive network connections.

This has me stumped. It could easily be a cygwin bug... and if it is I'm probably screwed...

Update: Just as I post this I find out a bit more. Entering a printf after the select function without a newline termination, causes the strings printed to only be displayed when and if a string with a newline arrives at stdout. And also, it exhibits the same SIGALRM vanish mentioned. The newline is essential...
Last edited on
Topic archived. No new replies allowed.