Files
hustoj/web/cppreference-zh/chmhelp/cpp-thread-shared_lock-try_lock.html
2025-08-01 12:57:54 +08:00

111 lines
6.1 KiB
HTML

<!DOCTYPE html>
<html lang="zh" dir="ltr" class="client-nojs" xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh">
<head><meta http-equiv="x-ua-compatible" content="ie=edge">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>std::shared_lock&lt;Mutex&gt;::try_lock</title>
<link rel="stylesheet" href="ext.css" />
<link rel="stylesheet" href="site_modules.css" />
</head>
<body class="mediawiki ltr sitedir-ltr ns-0 ns-subject page-cpp_thread_shared_lock_try_lock skin-cppreference2 action-view cpp-navbar">
<div id="cpp-content-base">
<div id="content"><a id="top"></a>
<h1 id="firstHeading" class="firstHeading"><span style="font-size:0.7em; line-height:130%">std::shared_lock&lt;Mutex&gt;::</span>try_lock</h1>
<div id="bodyContent">
<div id="contentSub"><span class="subpages">&lt; <a href="cpp.html">cpp</a>&lrm; | <a href="cpp-thread.html">thread</a>&lrm; | <a href="cpp-thread-shared_lock.html">shared lock</a></span></div>
<div id="mw-content-text" lang="zh" dir="ltr" class="mw-content-ltr" xml:lang="zh">
<table class="t-dcl-begin">
<tbody>
<tr class="t-dcl t-since-cxx14">
<td>
<div><span class="mw-geshi cpp source-cpp"><span class="kw4">bool</span> try_lock<span class="br0">(</span><span class="br0">)</span><span class="sy4">;</span></span></div>
</td>
<td class="t-dcl-nopad"></td>
<td><span class="t-mark-rev t-since-cxx14">(C++14 &#36215;)</span></td>
</tr>
<tr class="t-dcl-sep">
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<p>&#23581;&#35797;&#20197;&#20849;&#20139;&#27169;&#24335;&#38145;&#23450;&#20851;&#32852;&#20114;&#26021;&#32780;&#19981;&#38459;&#22622;&#12290;&#31561;&#25928;&#20110;&#35843;&#29992; <span class="t-c"><span class="mw-geshi cpp source-cpp">mutex<span class="br0">(</span><span class="br0">)</span><span class="sy2">-</span><span class="sy1">&gt;</span>try_lock_shared<span class="br0">(</span><span class="br0">)</span></span></span> &#12290;</p>
<p>&#33509;&#26080;&#20851;&#32852;&#20114;&#26021;&#65292;&#25110;&#20114;&#26021;&#24050;&#34987;&#38145;&#23450;&#65292;&#21017;&#25243;&#20986; <span class="t-lc"><a href="cpp-error-system_error.html">std::system_error</a></span> &#12290;</p>
<h3><span class="mw-headline" id=".E5.8F.82.E6.95.B0">&#21442;&#25968;</span></h3>
<p>&#65288;&#26080;&#65289;</p>
<h3><span class="mw-headline" id=".E8.BF.94.E5.9B.9E.E5.80.BC">&#36820;&#22238;&#20540;</span></h3>
<p>&#33509;&#24050;&#25104;&#21151;&#24471;&#21040;&#20114;&#26021;&#30340;&#25152;&#26377;&#26435;&#21017;&#20026; <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw2">true</span></span></span> &#65292;&#21542;&#21017;&#20026; <span class="t-c"><span class="mw-geshi cpp source-cpp"><span class="kw2">false</span></span></span> &#12290;</p>
<h3><span class="mw-headline" id=".E5.BC.82.E5.B8.B8">&#24322;&#24120;</span></h3>
<ul>
<li>&#20219;&#20309; <span class="t-c"><span class="mw-geshi cpp source-cpp">mutex<span class="br0">(</span><span class="br0">)</span><span class="sy2">-</span><span class="sy1">&gt;</span>try_lock_shared<span class="br0">(</span><span class="br0">)</span></span></span> &#25152;&#25243;&#30340;&#24322;&#24120;</li>
</ul>
<ul>
<li>&#33509;&#26080;&#20851;&#32852;&#20114;&#26021;&#65292;&#21017;&#25243;&#20986;&#20197; <span class="t-lc"><a href="cpp-error-errc.html">std::errc::operation_not_permitted</a></span> &#20026;&#38169;&#35823;&#30721;&#30340; <span class="t-lc"><a href="cpp-error-system_error.html">std::system_error</a></span></li>
</ul>
<ul>
<li>&#33509;&#20114;&#26021;&#24050;&#34987;&#38145;&#65292;&#21017;&#25243;&#20986;&#20197; <span class="t-lc"><a href="cpp-error-errc.html">std::errc::resource_deadlock_would_occur</a></span> &#20026;&#38169;&#35823;&#30721;&#30340; <span class="t-lc"><a href="cpp-error-system_error.html">std::system_error</a></span></li>
</ul>
<h3><span class="mw-headline" id=".E7.A4.BA.E4.BE.8B">&#31034;&#20363;</span></h3>
<table class="metadata plainlinks ambox mbox-small-left ambox-notice" style="">
<tr>
<td class="mbox-empty-cell"></td>
<td class="mbox-text" style="">&#26412;&#33410;&#26410;&#23436;&#25104;<br />
&#21407;&#22240;&#65306;&#26242;&#26080;&#31034;&#20363;</td>
</tr>
</table>
<h3><span class="mw-headline" id=".E5.8F.82.E9.98.85">&#21442;&#38405;</span></h3>
<table class="t-dsc-begin">
<tr class="t-dsc">
<td>
<div class="t-dsc-member-div">
<div><strong class="selflink"><span class="t-lines"><span>try_lock</span></span></strong></div>
</div>
</td>
<td>&#23581;&#35797;&#38145;&#23450;&#20851;&#32852;&#30340;&#20114;&#26021;<br />
<span class="t-mark">(&#20844;&#24320;&#25104;&#21592;&#20989;&#25968;)</span></td>
</tr>
<tr class="t-dsc">
<td>
<div class="t-dsc-member-div">
<div><a href="cpp-thread-shared_lock-lock.html"><span class="t-lines"><span>lock</span></span></a></div>
</div>
</td>
<td>&#38145;&#23450;&#20851;&#32852;&#30340;&#20114;&#26021;<br />
<span class="t-mark">(&#20844;&#24320;&#25104;&#21592;&#20989;&#25968;)</span></td>
</tr>
<tr class="t-dsc">
<td>
<div class="t-dsc-member-div">
<div><a href="cpp-thread-shared_lock-try_lock_for.html"><span class="t-lines"><span>try_lock_for</span></span></a></div>
</div>
</td>
<td>&#23581;&#35797;&#38145;&#23450;&#20851;&#32852;&#30340;&#20114;&#26021;&#65292;&#20197;&#25351;&#23450;&#26102;&#38271;<br />
<span class="t-mark">(&#20844;&#24320;&#25104;&#21592;&#20989;&#25968;)</span></td>
</tr>
<tr class="t-dsc">
<td>
<div class="t-dsc-member-div">
<div><a href="cpp-thread-shared_lock-try_lock_until.html"><span class="t-lines"><span>try_lock_until</span></span></a></div>
</div>
</td>
<td>&#23581;&#35797;&#38145;&#23450;&#20851;&#32852;&#30340;&#20114;&#26021;&#65292;&#30452;&#33267;&#25351;&#23450;&#30340;&#26102;&#38388;&#28857;<br />
<span class="t-mark">(&#20844;&#24320;&#25104;&#21592;&#20989;&#25968;)</span></td>
</tr>
<tr class="t-dsc">
<td>
<div class="t-dsc-member-div">
<div><a href="cpp-thread-shared_lock-unlock.html"><span class="t-lines"><span>unlock</span></span></a></div>
</div>
</td>
<td>&#35299;&#38145;&#20851;&#32852;&#30340;&#20114;&#26021;<br />
<span class="t-mark">(&#20844;&#24320;&#25104;&#21592;&#20989;&#25968;)</span></td>
</tr>
</table>
</div>
<div class="visualClear"></div>
</div>
</div>
</div>
</body>
</html>