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

Jonas Maebe jonas.maebe at elis.ugent.be
Wed Nov 10 14:32:18 CET 2010


On 10 Nov 2010, at 14:13, MegaBrutal wrote:

> 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).

That does not make any difference.

> 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.

It nevertheless does.

> Unless they open the file in
> sharing mode, but I suppose Rewrite doesn't enable file sharing by
> default.

On Unix-style OSes, Rewrite does not lock the file after opening it  
for writing (locking is a separate operation there).


Jonas



More information about the fpc-pascal mailing list