This isn't a fully worked solution, but it does demonstrate that it is reasonably easy to simulate the unix alarm function under Win32.
#! perl -slw
use strict;
use threads;
use threads::shared;
my $alarmFlag : shared = 0;
$SIG{__WARN__} = sub{ $alarmFlag = 1; };
sub myAlarm {
my( $procID, $timeout ) = @_;
async sub{
Win32::Sleep $timeout;
warn 'Timeout';
};
}
myAlarm( $$, 3000 );
while( not $alarmFlag ) {
print 'Waiting for the alarm at ', scalar localtime;
print 'Tum te, tum te, tum';
Win32::Sleep 1000;
}
print 'The alarm was raised', $/;
$alarmFlag = 0;
myAlarm( $$, 3000 );
while( not $alarmFlag ) {
print 'Waiting for the alarm at ', scalar localtime;
print 'Tum te, tum te, tum';
Win32::Sleep 1000;
}
print 'The alarm was raised', $/;
__END__
P:\test>alarm
Waiting for the alarm at Mon Dec 8 20:03:19 2003
Tum te, tum te, tum
Waiting for the alarm at Mon Dec 8 20:03:20 2003
Tum te, tum te, tum
Waiting for the alarm at Mon Dec 8 20:03:21 2003
Tum te, tum te, tum
The alarm was raised
Waiting for the alarm at Mon Dec 8 20:03:22 2003
Tum te, tum te, tum
Waiting for the alarm at Mon Dec 8 20:03:23 2003
Tum te, tum te, tum
Waiting for the alarm at Mon Dec 8 20:03:24 2003
Tum te, tum te, tum
The alarm was raised
This could be done a lot more effectively at the perl source level, and even made more sensible by a few pretty trivail patches to the perl sources. Changing the current default behaviour for most of the signals under Win32 which is set to die for pretty much anything other than a couple of exceptions -- which is just about the strangest choice of default behaviour possible as it make it impossible to code a more compatible workaround as you never get the opportunity to trap them? Strange choice.
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Hooray!
Wanted!
|