View source code
Display the source code in std/stdio.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
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.

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.

void lock (
  LockType lockType = LockType.readWrite,
  ulong start = 0LU,
  ulong length = 0LU
);

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.

Authors

Walter Bright, Andrei Alexandrescu, Alex Rønne Petersen

License

Boost License 1.0.