View source code Display the source code in std/stdio.d from which this page was generated on github. Improve this page Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

Function std.stdio.File.lock

Locks the specified file segment. If the file segment is already locked by another process, waits until the existing lock is released. If both start and length are zero, the entire file is locked.

Locks created using lock and tryLock have the following properties:

  • All locks are automatically released when the process terminates.
  • Locks are not inherited by child processes.
  • Closing a file will release all locks associated with the file. On POSIX, even locks acquired via a different File will be released as well.
  • Not all NFS implementations correctly implement file locking.

Prototype

void lock(
  LockType lockType = cast(LockType)1,
  ulong start = 0LU,
  ulong length = 0LU
);

Authors

Walter Bright, Andrei Alexandrescu, Alex Rønne Petersen

License

Boost License 1.0.

Comments