in reply to multiple infinitive loops

Threading is the obvious solution -- we'll help you if you show us what you tried -- but there might be alternatives. What kind of events are these?

Are they filehandles? Look at select() or its OO counterpart IO::Select. This only works on sockets in Windows, but there's a workaround to produce selectable pipes.

Are you on Windows? If these are Windows events or could be wrapped by a Windows event, you could access WaitForMultipleEvents via some Win32 module.

Can you specify a timeout? If so, you could use:

while(1) { Sub1(TIMEOUT); Sub2(TIMEOUT); }

Replies are listed 'Best First'.
Re^2: multiple infinitive loops
by ozkaa (Acolyte) on Oct 06, 2004 at 16:34 UTC
    Thanks for all the replies :)

    Im on windoze and using the
    Win32::OLE("WbemScripting.SWbemLocator");

    There is an event handler on it ExecNotificationQuery()->NextEvent();

    Which is locking everything up.

    I tried using a async threads but it still locks on the event.

    I will look at the WaitForMultipleEvents

    Many Thanks,
    Oscar

      I don't know anything about these scripting/locator things, but a quick look at the MSDN Library shows that NextEvent accepts a timeout. Therefore, a simple solution is:

      use constants TIMEOUT => 50; use constants wbemErrTimedOut => 0x80043001; while (1) { $o1 = $h1->NextEvent(TIMEOUT); ProcessEvent1($h1, $o1) if ($o1 != wbemErrTimedOut); $o2 = $h2->NextEvent(TIMEOUT); ProcessEvent2($h2, $o2) if ($o2 != wbemErrTimedOut); }
        yes, but I don't want it to timeout because its a critical thing to keep on monitoring the processes

        Oscar
      I was working on a perl script under windows recently and found that it blocked (wouldn't even time out) while attempting to connect to a network socket (This wasn't a problem on other platforms.). I ended up forking a child process to attempt the connection, and having the parent kill it if it went too long. From what you've shown so far, I would suggest trying to fork a child process for each of those event-handling tasks. That would allow both event handlers to be available and avoid blocking everything when one process blocks.