1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Class template wait_guard</title> 5<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../index.html" title="Chapter 1. Boost.Compute"> 8<link rel="up" href="../../boost_compute/reference.html#header.boost.compute.async.wait_guard_hpp" title="Header <boost/compute/async/wait_guard.hpp>"> 9<link rel="prev" href="wait_for_all.html" title="Function template wait_for_all"> 10<link rel="next" href="array.html" title="Class template array"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td> 15<td align="center"><a href="../../../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="wait_for_all.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../boost_compute/reference.html#header.boost.compute.async.wait_guard_hpp"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="array.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="refentry"> 26<a name="boost.compute.wait_guard"></a><div class="titlepage"></div> 27<div class="refnamediv"> 28<h2><span class="refentrytitle">Class template wait_guard</span></h2> 29<p>boost::compute::wait_guard — A guard object for synchronizing an operation on the device. </p> 30</div> 31<h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2> 32<div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: <<a class="link" href="../../boost_compute/reference.html#header.boost.compute.async.wait_guard_hpp" title="Header <boost/compute/async/wait_guard.hpp>">boost/compute/async/wait_guard.hpp</a>> 33 34</span><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> Waitable<span class="special">></span> 35<span class="keyword">class</span> <a class="link" href="wait_guard.html" title="Class template wait_guard">wait_guard</a> <span class="special">:</span> <span class="keyword">private</span> <span class="identifier">noncopyable</span> <span class="special">{</span> 36<span class="keyword">public</span><span class="special">:</span> 37 <span class="comment">// <a class="link" href="wait_guard.html#boost.compute.wait_guardconstruct-copy-destruct">construct/copy/destruct</a></span> 38 <a class="link" href="wait_guard.html#idm45549386341376-bb"><span class="identifier">wait_guard</span></a><span class="special">(</span><span class="keyword">const</span> <span class="identifier">Waitable</span> <span class="special">&</span><span class="special">)</span><span class="special">;</span> 39 <a class="link" href="wait_guard.html#idm45549386338928-bb"><span class="special">~</span><span class="identifier">wait_guard</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span> 40<span class="special">}</span><span class="special">;</span></pre></div> 41<div class="refsect1"> 42<a name="idm45849517333904"></a><h2>Description</h2> 43<p>The <a class="link" href="wait_guard.html" title="Class template wait_guard">wait_guard</a> class stores a waitable object representing an operation on a compute device (e.g. event, <a class="link" href="future.html" title="Class template future">future<T></a>) and calls its <code class="computeroutput">wait()</code> method when the guard object goes out of scope.</p> 44<p>This is useful for ensuring that an OpenCL operation completes before leaving the current scope and cleaning up any resources.</p> 45<p>For example: </p> 46<pre class="programlisting"><span class="comment">// enqueue a compute kernel for execution</span> 47<span class="identifier">event</span> <span class="identifier">e</span> <span class="special">=</span> <span class="identifier">queue</span><span class="special">.</span><span class="identifier">enqueue_nd_range_kernel</span><span class="special">(</span><span class="special">...</span><span class="special">)</span><span class="special">;</span> 48 49<span class="comment">// call e.wait() upon exiting the current scope</span> 50<span class="identifier">wait_guard</span><span class="special"><</span><span class="identifier">event</span><span class="special">></span> <span class="identifier">guard</span><span class="special">(</span><span class="identifier">e</span><span class="special">)</span><span class="special">;</span> 51</pre> 52<p><a class="link" href="wait_list.html" title="Class wait_list">wait_list</a>, wait_for_all() </p> 53<div class="refsect2"> 54<a name="idm45849517316128"></a><h3> 55<a name="boost.compute.wait_guardconstruct-copy-destruct"></a><code class="computeroutput">wait_guard</code> 56 public 57 construct/copy/destruct</h3> 58<div class="orderedlist"><ol class="orderedlist" type="1"> 59<li class="listitem"> 60<pre class="literallayout"><a name="idm45549386341376-bb"></a><span class="identifier">wait_guard</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">Waitable</span> <span class="special">&</span> waitable<span class="special">)</span><span class="special">;</span></pre>Creates a new <code class="computeroutput"><a class="link" href="wait_guard.html" title="Class template wait_guard">wait_guard</a></code> object for <code class="computeroutput">waitable</code>. </li> 61<li class="listitem"> 62<pre class="literallayout"><a name="idm45549386338928-bb"></a><span class="special">~</span><span class="identifier">wait_guard</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre> 63<p>Destroys the <code class="computeroutput"><a class="link" href="wait_guard.html" title="Class template wait_guard">wait_guard</a></code> object. The default implementation will call <code class="computeroutput">wait()</code> on the stored waitable object. </p> 64</li> 65</ol></div> 66</div> 67</div> 68</div> 69<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 70<td align="left"></td> 71<td align="right"><div class="copyright-footer">Copyright © 2013, 2014 Kyle Lutz<p> 72 Distributed under the Boost Software License, Version 1.0. (See accompanying 73 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) 74 </p> 75</div></td> 76</tr></table> 77<hr> 78<div class="spirit-nav"> 79<a accesskey="p" href="wait_for_all.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../boost_compute/reference.html#header.boost.compute.async.wait_guard_hpp"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="array.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 80</div> 81</body> 82</html> 83