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!


In reply to Re: Timeouts/timers on Win32 system by BrowserUk
in thread Timeouts/timers on Win32 system by Dovkont

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.