1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Chapter&#160;6.&#160;The trylock Functions</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="Unreliable Guide To Locking"><link rel="up" href="index.html" title="Unreliable Guide To Locking"><link rel="prev" href="cheatsheet.html" title="Chapter&#160;5.&#160;Cheat Sheet For Locking"><link rel="next" href="Examples.html" title="Chapter&#160;7.&#160;Common Examples"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter&#160;6.&#160;The trylock Functions</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="cheatsheet.html">Prev</a>&#160;</td><th width="60%" align="center">&#160;</th><td width="20%" align="right">&#160;<a accesskey="n" href="Examples.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="trylock-functions"></a>Chapter&#160;6.&#160;The trylock Functions</h1></div></div></div><p>
2   There are functions that try to acquire a lock only once and immediately
3   return a value telling about success or failure to acquire the lock.
4   They can be used if you need no access to the data protected with the lock
5   when some other thread is holding the lock. You should acquire the lock
6   later if you then need access to the data protected with the lock.
7  </p><p>
8    <code class="function">spin_trylock()</code> does not spin but returns non-zero if
9    it acquires the spinlock on the first try or 0 if not. This function can
10    be used in all contexts like <code class="function">spin_lock</code>: you must have
11    disabled the contexts that might interrupt you and acquire the spin lock.
12  </p><p>
13    <code class="function">mutex_trylock()</code> does not suspend your task
14    but returns non-zero if it could lock the mutex on the first try
15    or 0 if not. This function cannot be safely used in hardware or software
16    interrupt contexts despite not sleeping.
17  </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="cheatsheet.html">Prev</a>&#160;</td><td width="20%" align="center">&#160;</td><td width="40%" align="right">&#160;<a accesskey="n" href="Examples.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter&#160;5.&#160;Cheat Sheet For Locking&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;Chapter&#160;7.&#160;Common Examples</td></tr></table></div></body></html>
18