www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to open file with exclusive lock?

reply Charles Hixson via Digitalmars-d-learn writes:
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)?
Jul 12 2016
parent Lodovico Giaretta <lodovico giaretart.net> writes:
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
Jul 12 2016