code>trylock()</code>.</strong> To protect access to a shared resource, create a <code>$thread()</code> lock object and use it to guard access. Calling <code>.lock()</code> or <code>.unlock()</code> on a regular variable (like an array or scalar) will return an error.</p>
<p><strong>Canonical Example:</strong>
<div class="highlight"><pre><span></span><code>lock_obj = $thread();
lock_obj.lock();
/* ... perform thread-safe operations on shared data ... */
lock_obj.unlock();
</code></pre></div></p>
<p>See <a h