Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

(atl: flocks and processes) RE: race condition? - flock and $SIG{ALRM}

by atl (Pilgrim)
on Sep 17, 2000 at 21:26 UTC ( [id://32877]=note: print w/replies, xml ) Need Help??


in reply to race condition? - flock and $SIG{ALRM}

Letīs analyze what happens, if you get an flock and die before you can unset the alarm.

  • You got the lock, so no other process will write. Fine.
  • You die before unsetting the alarm. Since this is the first thing you do, thatīs equivalent to a timeout before. Fine.
  • What happens to the flock if your process dies? Since it is bound to an open filehandle, which getīs closed among process termination by the OS or even earlier by the perl interpreter (cleanup), it will simply vanish. The next process may claim the flock. Fine.
So far, youīre codeīs fine. As for the reliabilty of signals ... there is some coverage in the perldocs and here in the monastry. I donīt have a link handy, youīll have to try a search.

Have fun ...

Andreas
five days ītil YAPC::Europe ...

Update: BTW, using a nonblocking flock and putting the process to sleep for a random time would eliminate the need for signals. Try something like three tries with varying random sleeping times, if unsuccessful, give up (i.e. die). Adjust number of tries and sleeping time for your needs.

  • Comment on (atl: flocks and processes) RE: race condition? - flock and $SIG{ALRM}

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://32877]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (1)
As of 2024-04-16 21:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found