[#BloombergLP-bdls-FilesystemUtil-lock]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdls.adoc[bdls]::xref:BloombergLP/bdls/FilesystemUtil.adoc[FilesystemUtil]::lock
:relfileprefix: ../../../
:mrdocs:

Acquire a lock for the file with the specified `descriptor`&period;

== Synopsis

Declared in `&lt;bdls&lowbar;filesystemutil&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
static
int
lock(
    xref:BloombergLP/bdls/FilesystemUtil/FileDescriptor.adoc[FileDescriptor] descriptor,
    bool lockWriteFlag);
----

== Description

If `lockWriteFlag` is true, acquire an exclusive write lock&semi; otherwise acquire a (possibly) shared read lock&period; The calling thread will block until the lock is acquired&period; Return 0 on success, and a non&hyphen;zero value otherwise&period; Note that this operation locks the indicated file for use by the current _process_, but the behavior is unspecified (and platform&hyphen;dependent) when either attempting to lock `descriptor` multiple times, or attempting to lock another descriptor referring to the same file, within a single process&period;

== Return Value

0 on success, and a non&hyphen;zero value otherwise

== Parameters

[cols="1,4"]
|===
| Name| Description
| *descriptor*
| file descriptor of the file to lock
| *lockWriteFlag*
| `true` for an exclusive write lock&semi; `false` for a shared read lock
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
