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
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.
program FLockTest;
uses
BaseUnix, Unix;
var
InputFile: cInt;
S: String;
begin
InputFile:= 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.
_______________________________________________
fpc-devel maillist - fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel