[#BloombergLP-bslmt-LockGuardTryLock-2constructor]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslmt.adoc[bslmt]::xref:BloombergLP/bslmt/LockGuardTryLock.adoc[LockGuardTryLock]::LockGuardTryLock
:relfileprefix: ../../../
:mrdocs:

Create a scoped guard that conditionally manages the specified `lock` (if non&hyphen;null) and invokes `lock&hyphen;&gt;tryLock()` until the lock is acquired, or until the optionally specified `attempts` have been made to acquire the lock&period; If `attempts` is not specified only one attempt is made to acquire the lock&period; Supplying a null `lock` has no effect&period; The behavior is undefined unless `lock` (if non&hyphen;null) is not already locked by this thread and `0 &lt; attempts`&period; Note that `lock` must remain valid throughout the lifetime of this guard, or until `release` is called&period;

== Synopsis

Declared in `&lt;bslmt&lowbar;lockguard&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
explicit
LockGuardTryLock(
    T* lock,
    int attempts = 1);
----


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