public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* return value of getitimer after an alarm
@ 2019-02-24  9:15 Mike Gran via cygwin
  2019-02-24 10:14 ` Corinna Vinschen
  0 siblings, 1 reply; 4+ messages in thread
From: Mike Gran via cygwin @ 2019-02-24  9:15 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 400 bytes --]

Hi-

There is an unusual behaviour with setitimer/getitimer and I'm not
sure if it is a bug or not.

Basically, if I call setitimer to set an SIGALRM, and then call
getitimer *after* the alarm goes off, I rather expect the time I
receive from getitimer should be {tv_sec = 0, tv_usec = 0}, but, in
fact, it_value is the negative of the unix timestamp.

Attached is a test case.

Thanks,
Mike Gran




[-- Attachment #2: tmp.c --]
[-- Type: text/plain, Size: 1016 bytes --]

#include <sys/time.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/mman.h>

int loop = 1;

static void
handler(int sig, siginfo_t *si, void *unused)
{
  printf("Got SIGALRM at address: 0x%lx\n",
	 (long) si->si_addr);
  loop = 0;
}

int main(int argc, char **argv)
{

  struct sigaction sa;

  sa.sa_flags = SA_SIGINFO;
  sigemptyset(&sa.sa_mask);
  sa.sa_sigaction = handler;
  sigaction(SIGALRM, &sa, NULL);

  struct itimerval new_value, old_value;
  new_value.it_interval.tv_sec = 0;
  new_value.it_interval.tv_usec = 0;
  new_value.it_value.tv_sec = 0;
  new_value.it_value.tv_usec = 1000;
  setitimer(ITIMER_REAL, &new_value, &old_value);
  while (loop)
    ;
  printf("Loop is complete\n");
  int ret = getitimer(ITIMER_REAL, &old_value);
  printf("%d %ld %ld %ld %ld\n",
	 ret,
	 old_value.it_interval.tv_sec,
	 old_value.it_interval.tv_usec,
	 old_value.it_value.tv_sec,
	 old_value.it_value.tv_usec
	 );

  return 0;
}


[-- Attachment #3: Type: text/plain, Size: 219 bytes --]


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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: return value of getitimer after an alarm
  2019-02-24  9:15 return value of getitimer after an alarm Mike Gran via cygwin
@ 2019-02-24 10:14 ` Corinna Vinschen
  2019-02-24 17:27   ` Mike Gran via cygwin
  0 siblings, 1 reply; 4+ messages in thread
From: Corinna Vinschen @ 2019-02-24 10:14 UTC (permalink / raw)
  To: Mike Gran; +Cc: cygwin

[-- Attachment #1: Type: text/plain, Size: 830 bytes --]

On Feb 23 22:58, Mike Gran via cygwin wrote:
> Hi-
> 
> There is an unusual behaviour with setitimer/getitimer and I'm not
> sure if it is a bug or not.
> 
> Basically, if I call setitimer to set an SIGALRM, and then call
> getitimer *after* the alarm goes off, I rather expect the time I
> receive from getitimer should be {tv_sec = 0, tv_usec = 0}, but, in
> fact, it_value is the negative of the unix timestamp.
> 
> Attached is a test case.

Thanks for the testcase.  The reason for the problem is this:
I optimized a condition in Cygwin's POSIX timers "gettime" method.
I optimized it so effecively that it was practically invisible :}

I pushed a patch and uploaded new developer snapshots to
https://cygwin.com/snapshots/

Please test.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: return value of getitimer after an alarm
  2019-02-24 10:14 ` Corinna Vinschen
@ 2019-02-24 17:27   ` Mike Gran via cygwin
  2019-02-24 19:09     ` Corinna Vinschen
  0 siblings, 1 reply; 4+ messages in thread
From: Mike Gran via cygwin @ 2019-02-24 17:27 UTC (permalink / raw)
  To: cygwin

On Sun, Feb 24, 2019 at 10:18:58AM +0100, Corinna Vinschen wrote:
> On Feb 23 22:58, Mike Gran via cygwin wrote:
> > Hi-
> > 
> > There is an unusual behaviour with setitimer/getitimer and I'm not
> > sure if it is a bug or not.
> > 
> > Basically, if I call setitimer to set an SIGALRM, and then call
> > getitimer *after* the alarm goes off, I rather expect the time I
> > receive from getitimer should be {tv_sec = 0, tv_usec = 0}, but, in
> > fact, it_value is the negative of the unix timestamp.
> > 
> > Attached is a test case.
> 
> Thanks for the testcase.  The reason for the problem is this:
> I optimized a condition in Cygwin's POSIX timers "gettime" method.
> I optimized it so effecively that it was practically invisible :}
> 
> I pushed a patch and uploaded new developer snapshots to
> https://cygwin.com/snapshots/
> 
> Please test.

Works for me.  Thanks for your help.

-Mike Gran


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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: return value of getitimer after an alarm
  2019-02-24 17:27   ` Mike Gran via cygwin
@ 2019-02-24 19:09     ` Corinna Vinschen
  0 siblings, 0 replies; 4+ messages in thread
From: Corinna Vinschen @ 2019-02-24 19:09 UTC (permalink / raw)
  To: Mike Gran; +Cc: cygwin

[-- Attachment #1: Type: text/plain, Size: 1117 bytes --]

On Feb 24 08:57, Mike Gran via cygwin wrote:
> On Sun, Feb 24, 2019 at 10:18:58AM +0100, Corinna Vinschen wrote:
> > On Feb 23 22:58, Mike Gran via cygwin wrote:
> > > Hi-
> > > 
> > > There is an unusual behaviour with setitimer/getitimer and I'm not
> > > sure if it is a bug or not.
> > > 
> > > Basically, if I call setitimer to set an SIGALRM, and then call
> > > getitimer *after* the alarm goes off, I rather expect the time I
> > > receive from getitimer should be {tv_sec = 0, tv_usec = 0}, but, in
> > > fact, it_value is the negative of the unix timestamp.
> > > 
> > > Attached is a test case.
> > 
> > Thanks for the testcase.  The reason for the problem is this:
> > I optimized a condition in Cygwin's POSIX timers "gettime" method.
> > I optimized it so effecively that it was practically invisible :}
> > 
> > I pushed a patch and uploaded new developer snapshots to
> > https://cygwin.com/snapshots/
> > 
> > Please test.
> 
> Works for me.  Thanks for your help.

Thanks for testing!  Expect a 3.0.2 release soon.


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-02-24 19:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-24  9:15 return value of getitimer after an alarm Mike Gran via cygwin
2019-02-24 10:14 ` Corinna Vinschen
2019-02-24 17:27   ` Mike Gran via cygwin
2019-02-24 19:09     ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).