in reply to Re: Issue with time() in loop?
in thread Issue with time() in loop?

Well exit probably should have been return or something else but as I said it was a simple example.

Everyone seems to be suggesting work-arounds which is not what I was looking for. I can come up with numerous ways to make it work as I have already done but was more interested in the fact that there seems to be an issue with time() in a loop. I currently only check every 30 seconds so checking it too often should not be the issue. I was just wondering if anyone else had ever experienced this.

The background of my application was just history on how I came across this problem. I was not really asking for help with my application so posting a stripped down version would do me no good. Thanks to all for their suuggestions.

Replies are listed 'Best First'.
Re^3: Issue with time() in loop?
by BrowserUk (Patriarch) on Nov 13, 2005 at 23:56 UTC

    Basically, your post doesn't contain a testable sample, nor enough information to construct one, nor even enough to relate your perception of a problem with other bug reports. And in their absence, it is hard to see how time() would be failing.

  • Does it always fail, or only occasionally?
  • Have you managed to reproduce the problem in a simple example?
  • If you have, does it still fail if you run the failing code in a non-threaded script?

    In all honestly, it really seems more likely that the socket you are reading from stops receiving because the other end diconnected, or the socket froze, or you are running so many threads that one of them simply didn't get scheduled regularly enough.

    Thinking abstractly, it's possible that there is some buffer somewhere in perl that is used when fetching the time from OS, that might not be completely thread-safe, though I have never seen any similar effect and I've used time() in conjunction with threads a lot. Which OS are you running on?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re^3: Issue with time() in loop?
by Errto (Vicar) on Nov 14, 2005 at 04:55 UTC
    Here's the problem. You're stating that Perl's time function doesn't work in a loop. If that's true you should be able to post a small test program that illustrates this. For example, the following program does not use threads or sockets but relies on time() to terminate after 30 seconds:
    #!perl use strict; use warnings; my $endtime = time + 30; while (1) { if (time > $endtime) { print "30 seconds have passed\n"; exit; } sleep 1; }
    and lo and behold, it works.