Thread flock funktioniert nicht (64 answers)
Opened by x-man at 2006-04-17 19:11

pq
 2006-04-18 16:31
#7354 #7354
User since
2003-08-04
12209 Artikel
Admin1
[Homepage]
user image
[quote=master,18.04.2006, 13:33]Bin mir nicht ganz sicher aber denke die Datei wird gelöscht und dann neu erzeugt. Bei sysopen ist das jedenfalls nicht so.
[/quote]
master, bitte...
mit flock() kannst du ohne race-condition daten verarbeiten. und
wenn zwei prozesse noch so schnell dasselbe tun. genau dafür ist
flock doch da, denn es ist eine atomare operation.
ich warte immer noch auf konkreten code und eine demonstration.
bzw.: wo soll bei folgendem code eine race-condition sein?
Code: (dl )
1
2
3
4
5
6
7
8
9
10
use Fcntl qw(:flock :seek);
open my $fh, "+<", "datei" or die $!;
flock $fh, LOCK_EX;
seek $fh, 0, SEEK_SET;
chomp(my $count = <$fh>);
$count++;
seek $fh, 0, SEEK_SET;
truncate $fh, 0;
print $fh "$count\n";
close $fh;
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: Wiki:Wie frage ich & perlintro Wiki:brian's Leitfaden für jedes Perl-Problem

View full thread flock funktioniert nicht