[fpc-pascal] (Unix) file locking

Mark Morgan Lloyd markMLl.fpc-pascal at telemetry.co.uk
Mon Jun 20 21:44:17 CEST 2016

Jonas Maebe wrote:
> On 20/06/16 11:28, Mark Morgan Lloyd wrote:
>> I'm approaching a situation where up to four identical processes will be
>> reading and writing the same files. There will be process-level
>> synchronisation which should prevent clashes, but I'd still like to add
>> locking at the file level.
> If you use sysutils.fileopen, file locking will automatically be used 
> based on fmShare* constants you specify: 
> http://www.freepascal.org/docs-html/current/rtl/sysutils/fileopen.html

I think I should have said that I needed locking at the record level, 
where each record is 256 bytes. When I referred to "file" I meant that 
this was the low-level storage layer, with several other layers on top 
of it; records will be written and read in indeterminate order, the file 
won't be written by one process and read by the rest.

Each of the four programs (assumed to be running on the same system, 
i.e. no NFS etc.) will be managing its own advisory locking using shared 
memory. However for cases where one of them erroneously tries to ignore 
the custom advisory lock I want to be able to lock individual records in 
the common file.

The file represents a mainframe disk subsystem, around which up to four 
systems operated. Each system had two CPUs, with a multitasking OS. 
There's a lot to go wrong...

Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]

More information about the fpc-pascal mailing list