[fpc-devel] FpFlock with Text as argument
amir
amir at aavani.net
Thu May 8 03:58:16 CEST 2008
Hi,
I don't know if it is a bug or I am using fpflock incorrectly. I wanted =
to use fpflock to lock a file (and be sure that only one process at a =
time can have access to my file).
At first, I tried AssignFile and passed the TextFile(Text) variable to =
fpflock with LOCK_EX. It didn't work and both processes can access the file.
Both print "After Flock".
Then I modify the code, and used fpopen instead of AssignFile and passed =
the cInt variable to fpflock . This worked.
I attached the codes of both experiments.
Amir
-------------- next part --------------
program FLockTest;
uses
BaseUnix, Unix;
var
InputFile: TextFile;
S: String;
=
begin
AssignFile (InputFile, 'Lock.txt');
WriteLn ('Before Flock');
Flush (Output);
Fpflock (InputFile, LOCK_EX);
WriteLn ('After Flock');
Flush (Output);
ReadLn (S);
WriteLn (S);
=
CloseFile (InputFile);
WriteLn ('After CloseFile');
end.
-------------- next part --------------
program FLockTest;
uses
BaseUnix, Unix;
var
InputFile: cInt;
S: String;
=
begin
InputFile:=3D fpOPen ('Lock.txt', O_WrOnly);
WriteLn ('Before Flock');
Flush (Output);
Fpflock (InputFile, LOCK_EX);
WriteLn ('After Flock');
Flush (Output);
ReadLn (S);
WriteLn (S);
=
fpClose (InputFile);
WriteLn ('After CloseFile');
end.
More information about the fpc-devel
mailing list