[fpc-pascal] Is System.IOResult thread-safe? (If not, I need to replace it.)

MegaBrutal megabrutal at gmail.com
Wed Nov 10 14:13:39 CET 2010


2010/11/10 Jonas Maebe <jonas.maebe at elis.ugent.be>:
> The problem is that calling rewrite on an already opened file works fine (at
> least on Unix platforms). This program runs fine on Mac OS X and Linux:
>
> var
>  f: file;
> begin
> {$i+}
>  assign(f, 'test.txt');
>  rewrite(f);
>  rewrite(f);
> end.
>
> That's why I suggested the sysutils route, which enables you to specify the
> locking policy.

I should have noted this, but my "LockFile" is not a global variable.
It's a field of my object. So each object instance has its own
"LockFile", and threads create their own instance of the object.
However, they try to open the same file on the file system, but with
different file descriptors (under file descriptor, now I mean a Pascal
"file" typed variable).

The little program that would simulate it:

var
 f, g: file;
begin
{$i+}
 assign(f, 'test.txt');
 assign(g,'test.txt');
 rewrite(f,1);
 rewrite(g,1);
end.

I think it shouldn't work on any OS. Unless they open the file in
sharing mode, but I suppose Rewrite doesn't enable file sharing by
default.

Thanks for your suggestion anyway, I guess FileOpen would really
eliminate my problem, however not because of file sharing, like you
suspect.



More information about the fpc-pascal mailing list