143 lines
9.8 KiB
HTML
143 lines
9.8 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::condition_variable_any</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_condition_variable_any 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::</span>condition_variable_any</h1>
|
|
<div id="bodyContent">
|
|
<div id="contentSub"><span class="subpages">< <a href="cpp.html">cpp</a>‎ | <a href="cpp-thread.html">thread</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-dsc-header">
|
|
<td>
|
|
<div>定义于头文件 <code><a href="cpp-header-condition_variable.html"><condition_variable></a></code></div>
|
|
</td>
|
|
<td></td>
|
|
<td></td>
|
|
</tr>
|
|
<tr class="t-dcl t-since-cxx11">
|
|
<td>
|
|
<div><span class="mw-geshi cpp source-cpp"><span class="kw1">class</span> condition_variable_any<span class="sy4">;</span></span></div>
|
|
</td>
|
|
<td class="t-dcl-nopad"></td>
|
|
<td><span class="t-mark-rev t-since-cxx11">(C++11 起)</span></td>
|
|
</tr>
|
|
<tr class="t-dcl-sep">
|
|
<td></td>
|
|
<td></td>
|
|
<td></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<p><code>condition_variable_any</code> 类是 <span class="t-lc"><a href="cpp-thread-condition_variable.html">std::condition_variable</a></span> 的泛化。相对于只在 <span class="t-c"><span class="mw-geshi cpp source-cpp"><a href="cpp-thread-unique_lock.html"><span class="kw2167">std::<span class="me2">unique_lock</span></span></a><span class="sy1"><</span><a href="cpp-thread-mutex.html"><span class="kw2154">std::<span class="me2">mutex</span></span></a><span class="sy1">></span></span></span> 上工作的 <span class="t-lc"><a href="cpp-thread-condition_variable.html">std::condition_variable</a></span> , <code>condition_variable_any</code> 能在任何满足<a href="cpp-named_req-BasicLockable.html"><span style="font-style:italic">基本可锁定</span> <span style="font-family: Georgia, 'DejaVu Serif', serif; font-style:italic">(BasicLockable)</span></a> 要求的锁上工作。</p>
|
|
<p>条件变量语义描述见 <span class="t-lc"><a href="cpp-thread-condition_variable.html">std::condition_variable</a></span> 。</p>
|
|
<p>类 <code>std::condition_variable_any</code> 是<a href="cpp-named_req-StandardLayoutType.html"><span style="font-style:italic">标准布局类型</span> <span style="font-family: Georgia, 'DejaVu Serif', serif; font-style:italic">(StandardLayoutType)</span></a> 。它非<a href="cpp-named_req-CopyConstructible.html"><span style="font-style:italic">可复制构造</span> <span style="font-family: Georgia, 'DejaVu Serif', serif; font-style:italic">(CopyConstructible)</span></a> 、<a href="cpp-named_req-MoveConstructible.html"><span style="font-style:italic">可移动构造</span> <span style="font-family: Georgia, 'DejaVu Serif', serif; font-style:italic">(MoveConstructible)</span></a> 、<a href="cpp-named_req-CopyAssignable.html"><span style="font-style:italic">可复制赋值</span> <span style="font-family: Georgia, 'DejaVu Serif', serif; font-style:italic">(CopyAssignable)</span></a> 或<a href="cpp-named_req-MoveAssignable.html"><span style="font-style:italic">可移动赋值</span> <span style="font-family: Georgia, 'DejaVu Serif', serif; font-style:italic">(MoveAssignable)</span></a> 。</p>
|
|
<p>若锁是 <span class="t-lc"><a href="cpp-thread-unique_lock.html">std::unique_lock</a></span> ,则 <span class="t-lc"><a href="cpp-thread-condition_variable.html">std::condition_variable</a></span> 可能提供更好的性能。</p>
|
|
<h3><span class="mw-headline" id=".E6.88.90.E5.91.98.E5.87.BD.E6.95.B0">成员函数</span></h3>
|
|
<table class="t-dsc-begin">
|
|
<tr class="t-dsc">
|
|
<td>
|
|
<div class="t-dsc-member-div t-dsc-member-nobold-div">
|
|
<div><a href="cpp-thread-condition_variable_any-condition_variable_any.html"><span class="t-lines"><span>(构造函数)</span></span></a></div>
|
|
</div>
|
|
</td>
|
|
<td>构造对象<br />
|
|
<span class="t-mark">(公开成员函数)</span></td>
|
|
</tr>
|
|
<tr class="t-dsc">
|
|
<td>
|
|
<div class="t-dsc-member-div t-dsc-member-nobold-div">
|
|
<div><a href="cpp-thread-condition_variable_any-~condition_variable_any.html"><span class="t-lines"><span>(析构函数)</span></span></a></div>
|
|
</div>
|
|
</td>
|
|
<td>析构对象<br />
|
|
<span class="t-mark">(公开成员函数)</span></td>
|
|
</tr>
|
|
<tr class="t-dsc">
|
|
<td>
|
|
<div class="t-dsc-member-div">
|
|
<div><span class="t-lines"><span>operator=</span></span></div>
|
|
<div><span class="t-lines"><span><span class="t-cmark">[被删除]</span></span></span></div>
|
|
</div>
|
|
</td>
|
|
<td>不可复制赋值<br />
|
|
<span class="t-mark">(公开成员函数)</span></td>
|
|
</tr>
|
|
<tr>
|
|
<td colspan="2">
|
|
<h5><span class="mw-headline" id=".E9.80.9A.E7.9F.A5">通知</span></h5>
|
|
</td>
|
|
</tr>
|
|
<tr class="t-dsc">
|
|
<td>
|
|
<div class="t-dsc-member-div">
|
|
<div><a href="cpp-thread-condition_variable_any-notify_one.html"><span class="t-lines"><span>notify_one</span></span></a></div>
|
|
</div>
|
|
</td>
|
|
<td>通知一个等待的线程<br />
|
|
<span class="t-mark">(公开成员函数)</span></td>
|
|
</tr>
|
|
<tr class="t-dsc">
|
|
<td>
|
|
<div class="t-dsc-member-div">
|
|
<div><a href="cpp-thread-condition_variable_any-notify_all.html"><span class="t-lines"><span>notify_all</span></span></a></div>
|
|
</div>
|
|
</td>
|
|
<td>通知所有等待的线程<br />
|
|
<span class="t-mark">(公开成员函数)</span></td>
|
|
</tr>
|
|
<tr>
|
|
<td colspan="2">
|
|
<h5><span class="mw-headline" id=".E7.AD.89.E5.BE.85">等待</span></h5>
|
|
</td>
|
|
</tr>
|
|
<tr class="t-dsc">
|
|
<td>
|
|
<div class="t-dsc-member-div">
|
|
<div><a href="cpp-thread-condition_variable_any-wait.html"><span class="t-lines"><span>wait</span></span></a></div>
|
|
</div>
|
|
</td>
|
|
<td>阻塞当前线程,直到条件变量被唤醒<br />
|
|
<span class="t-mark">(公开成员函数)</span></td>
|
|
</tr>
|
|
<tr class="t-dsc">
|
|
<td>
|
|
<div class="t-dsc-member-div">
|
|
<div><a href="cpp-thread-condition_variable_any-wait_for.html"><span class="t-lines"><span>wait_for</span></span></a></div>
|
|
</div>
|
|
</td>
|
|
<td>阻塞当前线程,直到条件变量被唤醒,或到指定时限时长后<br />
|
|
<span class="t-mark">(公开成员函数)</span></td>
|
|
</tr>
|
|
<tr class="t-dsc">
|
|
<td>
|
|
<div class="t-dsc-member-div">
|
|
<div><a href="cpp-thread-condition_variable_any-wait_until.html"><span class="t-lines"><span>wait_until</span></span></a></div>
|
|
</div>
|
|
</td>
|
|
<td>阻塞当前线程,直到条件变量被唤醒,或直到抵达指定时间点<br />
|
|
<span class="t-mark">(公开成员函数)</span></td>
|
|
</tr>
|
|
</table>
|
|
<h3><span class="mw-headline" id=".E6.B3.A8.E8.A7.A3">注解</span></h3>
|
|
<p><code>std::condition_variable_any</code> 能与 <span class="t-lc"><a href="cpp-thread-shared_lock.html">std::shared_lock</a></span> 一同使用,以在 <span class="t-lc"><a href="cpp-thread-shared_mutex.html">std::shared_mutex</a></span> 上以共享所有权模式等待。</p>
|
|
<p><code>std::condition_variable_any</code> 与定制<a href="cpp-named_req-Lockable.html"><span style="font-style:italic">可锁定</span> <span style="font-family: Georgia, 'DejaVu Serif', serif; font-style:italic">(Lockable)</span></a> 类型的一种可行使用是提供便利的可中断等待:定制所操作将按期待锁定关联互斥,并在收到中断信号时进行必要的设置,以通知此条件变量。<sup id="cite_ref-1" class="reference"><a href="cpp-thread-condition_variable_any.html#cite_note-1">[1]</a></sup></p>
|
|
<h3><span class="mw-headline" id=".E5.BC.95.E7.94.A8">引用</span></h3>
|
|
<ol class="references">
|
|
<li id="cite_note-1"><span class="mw-cite-backlink"><a href="cpp-thread-condition_variable_any.html#cite_ref-1">↑</a></span> <span class="reference-text">A. Williams (2012), "C++ concurrency in action" 9.2.4 Interupting a wait on std::condition_variable_any</span></li>
|
|
</ol>
|
|
</div>
|
|
<div class="visualClear"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|