[#BloombergLP-bslmt-WriteLockGuardTryLock-2constructor] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslmt.adoc[bslmt]::xref:BloombergLP/bslmt/WriteLockGuardTryLock.adoc[WriteLockGuardTryLock]::WriteLockGuardTryLock :relfileprefix: ../../../ :mrdocs: Create a guard that tries to acquire a write lock on `lock`. == Synopsis Declared in `<bslmt_writelockguard.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- explicit WriteLockGuardTryLock( T* lock, int attempts = 1); ---- == Description Create a scoped guard that conditionally manages the specified `lock` (if non‐null) and invokes `lock‐>tryLockWrite()` until the lock is acquired for writing, or until the optionally specified `attempts` have been made to acquire the lock. If `attempts` is not specified only one attempt is made to acquire the lock. Supplying a null `lock` has no effect. The behavior is undefined unless `lock` (if non‐null) is not already locked by this thread and `0 < attempts`. Note that `lock` must remain valid throughout the lifetime of this guard, or until `release` is called. == Parameters [cols="1,4"] |=== | Name| Description | *lock* | lock object to try‐lock for writing; may be null | *attempts* | maximum number of try‐lock attempts |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#