Timer::HiRes interval timers

Timer::HiRes interval timers

am 21.12.2008 07:28:43 von Mike

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



charset=3Dus-ascii">
Message




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

class=3D051141406-21122008> 

my =
"dumbed down"=20
code:

 

use Time::HiRes qw( setitimer =
ITIMER_REAL=20
);

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

 

size=3D2>Results in this=20
error:

size=3D2> 

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

size=3D2> 

Any =
insight is=20
appreciated.

size=3D2> 

size=3D2>Thanks,

size=3D2>Mike


------=_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@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1142236349==--

Re: Timer::HiRes interval timers

am 21.12.2008 19:51:26 von Bill Luebkert

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 ($@) {
my $diff = Win32::GetTickCount () - $pt0;
printf "Actual time = %.3f sec\n", $diff / 1000;
print "Timed out at ($x)\n$@";
die "eval timeout\n" if $@ =~ /5 second alarm went off/i;
} else {
print "Didn't timeout ($x)\n";
}

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs