Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > a Post-script to flocking question

Reply
Thread Tools

a Post-script to flocking question

 
 
Dick Rosser
Guest
Posts: n/a
 
      11-13-2003
Sorry, I also meant to ask if there is any
error trapping with flock. If a second person
accesses the database befor the first persons lock
is in place, is the database corrupted. How does one
work around this?

Regards
Dick Rosser
webmasterone@kidwatch-uk,net


 
Reply With Quote
 
 
 
 
Tassilo v. Parseval
Guest
Posts: n/a
 
      11-13-2003
Also sprach Dick Rosser:

> Sorry, I also meant to ask if there is any
> error trapping with flock. If a second person
> accesses the database befor the first persons lock
> is in place, is the database corrupted. How does one
> work around this?


You don't, but flock() does. This is exactly the scenario it is used
for. Since locks are usually only advisable, both parties accessing the
database have to use flock(). If there is already a lock on it, the
other process will block until the lock is released. You can also do
non-blocking locks in which case flock() returns a false value if the
file is already locked:

use Fcntl qw(:flock);
...
flock FH, LOCK_EX|LOCK_NB or die $!;

This can be used for allowing the waiting processes do something useful
in the meantime:

while (! flock FH, LOCK_EX|LOCK_NB) {
warn $!;
# do some useful stuff here
}
# and now we have the lock and can work with the file

Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus}) !JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexi ixesixeseg;y~\n~~dddd;eval
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
WHY customers are flocking away from Windows Roman Computer Support 8 10-29-2005 01:00 PM
Question on Transcender Question :-) eddiec MCSE 6 05-20-2004 06:59 AM
Question re: features of the 831 router (also a 924 question) Wayne Cisco 0 03-02-2004 07:57 PM
Flocking Advise \Dandy\ Randy Perl Misc 8 09-10-2003 09:36 AM
Final "Flocking" Script \Dandy\ Randy Perl Misc 13 08-08-2003 12:13 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57