How to open file with exclusive lock?

Lodovico Giaretta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 12 12:02:06 PDT 2016


On Tuesday, 12 July 2016 at 18:54:18 UTC, Charles Hixson wrote:
> I want to open a file with an exclusive lock.  It would be 
> important that no other thread be able to access the file in 
> write mode, and desirable that no other thread be able to 
> access the file in read mode.  (Ditto for other processes.)
>
> stdio.file.lock (or is it stdio.file.File.lock?) seems to 
> demand a range of chunks to lock, but the file is not fixed in 
> length. Is it appropriate to just specify the maximum possible 
> number of bytes (i.e. ulong.max)?

 From the lock[1] description:

> If both start and length are zero, the entire file is locked.

[1] https://dlang.org/phobos/std_stdio.html#.File.lock


More information about the Digitalmars-d-learn mailing list