[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 13:58:47 CET 2010

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

> Well, my object should keep the lockfile opened as long as it's
> working. If the file has already existed, but Rewrite is able to lock
> it, that means that my application was shut down improperly. But it's
> not a problem. Actually, the operating system should refuse to open
> the file if a 2nd thread tries to open it. To sum it up, my code
> doesn't work like you assume, that it creates and closes a file, and
> it checks for the existence of the file to check whether it can work
> on the object; instead it opens the file, and keeps it opened until it
> finishes its work, then closes and deletes the file.

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:

   f: file;
   assign(f, 'test.txt');

That's why I suggested the sysutils route, which enables you to  
specify the locking policy.


More information about the fpc-pascal mailing list