Timer::HiRes interval timers

This is a multi-part message in MIME format.

--===============1142236349==
Content-Type: multipart/alternative;
boundary="----=_NextPart_000_0064_01C9630B.768C0E10"

This is a multi-part message in MIME format.

------=_NextPart_000_0064_01C9630B.768C0E10
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit

I'm using perl 5.10 with Tkx and am trying to implement an interval
timer on my Win32 (XP) box. After reading the documentation, I'm only
attempting to use the ITIMER_REAL because I'm on a Win32 platform.

my "dumbed down" code:

use Time::HiRes qw( setitimer ITIMER_REAL );

$SIG{ALRM} = sub { print time, "\n" };
setitimer(ITIMER_REAL, 10, 2.5);


Results in this error:

Your vendor has not defined Time::HiRes macro ITIMER_REALPROF...

Any insight is appreciated.

Thanks,
Mike

------=_NextPart_000_0064_01C9630B.768C0E10
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">
<TITLE>Message</TITLE>

<META content=3D"MSHTML 6.00.5730.13" name=3DGENERATOR></HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D051141406-21122008>I'm =
using perl 5.10
with Tkx and am trying to implement an interval timer on my Win32 (XP)
box.  After reading the documentation, I'm only attempting to =
use the
ITIMER_REAL because I'm on a Win32 platform.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN
class=3D051141406-21122008></SPAN></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D051141406-21122008>my =
"dumbed down"
code:</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>use Time::HiRes qw( setitimer =
ITIMER_REAL
);<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>  $SIG{ALRM} =3D sub { print time, =
"\n"
};<BR>  setitimer(ITIMER_REAL, 10, 2.5);<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><SPAN class=3D051141406-21122008><FONT face=3DArial =
size=3D2>Results in this
error:</FONT></SPAN></DIV>
<DIV><SPAN class=3D051141406-21122008><FONT face=3DArial
size=3D2></FONT></SPAN> </DIV>
<DIV><SPAN class=3D051141406-21122008><FONT face=3DArial size=3D2>Your =
vendor has not
defined Time::HiRes macro ITIMER_REALPROF...</FONT></SPAN></DIV>
<DIV><SPAN class=3D051141406-21122008><FONT face=3DArial
size=3D2></FONT></SPAN> </DIV>
<DIV><SPAN class=3D051141406-21122008><FONT face=3DArial size=3D2>Any =
insight is
appreciated.</FONT></SPAN></DIV>
<DIV><SPAN class=3D051141406-21122008><FONT face=3DArial
size=3D2></FONT></SPAN> </DIV>
<DIV><SPAN class=3D051141406-21122008><FONT face=3DArial
size=3D2>Thanks,</FONT></SPAN></DIV>
<DIV><SPAN class=3D051141406-21122008><FONT face=3DArial
size=3D2>Mike</FONT></SPAN></DIV></FONT></DIV></BODY></HTML>

------=_NextPart_000_0064_01C9630B.768C0E10--


--===============1142236349==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1142236349==--
Mike [ So, 21 Dezember 2008 07:28 ] [ ID #1981932 ]

Re: Timer::HiRes interval timers

Mike wrote:
> I'm using perl 5.10 with Tkx and am trying to implement an interval
> timer on my Win32 (XP) box. After reading the documentation, I'm only
> attempting to use the ITIMER_REAL because I'm on a Win32 platform.
>
> my "dumbed down" code:
>
> use Time::HiRes qw( setitimer ITIMER_REAL );
> $SIG{ALRM} = sub { print time, "\n" };
> setitimer(ITIMER_REAL, 10, 2.5);

Windoze doesn't have a signal mechanism, so alarms don't really work
and itimers aren't implemented.

You can use the alarm function (seconds resolution) if you're not doing
anything that will block your code because it's faked in Perl.

What specifically are you using it for and what resolution do you need ?


You can use Win32::GetTickCount to get more accurate timing, but it's
not an alarm - just a timer.

Here's some sample code to illustrate alarm and GetTickCount:

use strict;
use warnings;

my $x = 0;
my $pt0 = Win32::GetTickCount ();

eval {
$SIG{ALRM} = sub { die "5 second alarm went off\n" };
alarm 5;
while (1) {

# if you should block on an IO in here, you're stuck

$x += 1;
print "x=$x\n";
sleep 1;
}
alarm 0;
};
if ($ [at] ) {
my $diff = Win32::GetTickCount () - $pt0;
printf "Actual time = %.3f sec\n", $diff / 1000;
print "Timed out at ($x)\n$ [at] ";
die "eval timeout\n" if $ [at] =~ /5 second alarm went off/i;
} else {
print "Didn't timeout ($x)\n";
}

_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Bill Luebkert [ So, 21 Dezember 2008 19:51 ] [ ID #1981933 ]
Perl » gmane.comp.lang.perl.active-perl » Timer::HiRes interval timers

Vorheriges Thema: Graeme Lawry/AU/ITS/ORICA is out of the office
Nächstes Thema: Question about Net::FTPSSL