Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Ways to sequence calls from multiple processes

by DaWolf (Curate)
on Nov 28, 2004 at 23:10 UTC ( [id://410838]=note: print w/replies, xml ) Need Help??


in reply to Ways to sequence calls from multiple processes

Just a little reminder: you forgot to explicitly unlock the file after the operation. I think this may be optional, but IMHO it always a good thing to do it explicitly, so your code should look like:
open(FH, ">>lock.txt") or die "can't open lock.txt: $!\n"; flock(FH, 2) or die "Can't flock lock.txt: $!\n"; now_access_the_common_resource(); flock(FH, LOCK_UN); close(FH);
Best regards,

Replies are listed 'Best First'.
Re^2: Ways to sequence calls from multiple processes
by Anonymous Monk on Nov 28, 2004 at 23:17 UTC
    although, it may actually be better to not explicitly unlock in this case. For example, if someone else is waiting for the lock on FH, they might conceivably get the lock after the LOCK_UN step, but before the close(FH) AND therefore before the first process has flushed it's write operations to disk. alternatives are using autoflushing ($| = 1) or using the FileHandle->autoflush() method.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-04-24 04:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found