in reply to Non-Blocking Semaphore

Have you tried using alarm()?

# untested with your particular situation, but should be a guide. eval { local $SIG{ALRM} = sub { die "lock\n" }; # NB: \n required alarm 5; flock(LOCK, LOCK_EX | LOCK_NB); alarm 0; }; if ($@) { die unless $@ eq "lock\n"; } else { # keep going }

Cheers,
KM

Replies are listed 'Best First'.
RE: Re: Non-Blocking Semaphore
by maverick (Curate) on Aug 26, 2000 at 03:52 UTC
    That would do the trick. But only if timing isn't critical as alarm isn't precise (like sleep) and if your timeout is always some number of whole seconds.

    /\/\averick

      Time::HiRes offers ualarm if you want and your OS has the command available. You can import their alarm as well.

      Yet another solution on systems which support SysV semantics (Linux does, Windows probably doesn't...) is to use IPC::Semaphore.