[#BloombergLP-bdls-FilesystemUtil-tryLock] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdls.adoc[bdls]::xref:BloombergLP/bdls/FilesystemUtil.adoc[FilesystemUtil]::tryLock :relfileprefix: ../../../ :mrdocs: Acquire a lock for the file with `descriptor` if it is available. == Synopsis Declared in `<bdls_filesystemutil.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- static int tryLock( xref:BloombergLP/bdls/FilesystemUtil/FileDescriptor.adoc[FileDescriptor] descriptor, bool lockWriteFlag); ---- == Description Acquire a lock for the file with the specified `descriptor` if it is currently available. If the specified `lockWriteFlag` is true, acquire an exclusive write lock unless another process has any type of lock on the file. If `lockWriteFlag` is false, acquire a shared read lock unless a process has a write lock. This method will not block. Return 0 on success, `k_ERROR_LOCKING_CONFLICT` if the platform reports the lock could not be acquired because another process holds a conflicting lock, and a negative value for any other kind of error. Note that this operation locks the indicated file for the current _process_, but the behavior is unspecified (and platform‐dependent) when either attempting to lock `descriptor` multiple times, or attempting to lock another descriptor referring to the same file, within a single process. == Return Value 0 on success, `k_ERROR_LOCKING_CONFLICT` on a conflicting lock, and a negative value for any other error == Parameters [cols="1,4"] |=== | Name| Description | *descriptor* | file descriptor of the file to lock | *lockWriteFlag* | `true` for an exclusive write lock; `false` for a shared read lock |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#