Click here to Skip to main content
15,887,596 members
Articles / Programming Languages / C++

Cross thread calls in native C++

Rate me:
Please Sign up or sign in to vote.
4.85/5 (38 votes)
19 Jul 2007Apache20 min read 117.8K   1.2K   96  
An article which discusses the need for synchronization in multi-threaded applications, and features a generic framework for making calls across threads: ThreadSynch.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>ThreadSynch: ExceptionExpecter&lt; E, BOOST_PP_ITERATION()&gt; Class Template Reference</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.1-p1 -->
<div class="tabs">
  <ul>
    <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
    <li><a href="namespaces.html"><span>Namespaces</span></a></li>
    <li id="current"><a href="annotated.html"><span>Classes</span></a></li>
    <li><a href="files.html"><span>Files</span></a></li>
  </ul></div>
<div class="tabs">
  <ul>
    <li><a href="annotated.html"><span>Class&nbsp;List</span></a></li>
    <li><a href="hierarchy.html"><span>Class&nbsp;Hierarchy</span></a></li>
    <li><a href="functions.html"><span>Class&nbsp;Members</span></a></li>
  </ul></div>
<h1>ExceptionExpecter&lt; E, BOOST_PP_ITERATION()&gt; Class Template Reference</h1><!-- doxytag: class="ExceptionExpecter&lt; E, BOOST_PP_ITERATION()&gt;" --><code>#include &lt;ExceptionExpecter_template.h&gt;</code>
<p>
<a href="class_exception_expecter_3_01_e_00_01_b_o_o_s_t___p_p___i_t_e_r_a_t_i_o_n()_4-members.html">List of all members.</a><table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_exception_expecter_3_01_e_00_01_b_o_o_s_t___p_p___i_t_e_r_a_t_i_o_n()_4.html#937fd96f92730d74258e35978f0325de">ExceptionExpecter</a> (boost::function&lt; void(details::CaughtExceptionType)&gt; onCompleteFunctor)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_exception_expecter_3_01_e_00_01_b_o_o_s_t___p_p___i_t_e_r_a_t_i_o_n()_4.html#afb6f0922388eb72939bc6c78b755efb">~ExceptionExpecter</a> ()</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_exception_expecter_3_01_e_00_01_b_o_o_s_t___p_p___i_t_e_r_a_t_i_o_n()_4.html#8344e702c16a56271d550db49f4d4b9f">BOOST_PP_REPEAT_2ND</a> (BOOST_PP_ITERATION(), THROWEX, throwEx) void execute(boost</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_exception_expecter_3_01_e_00_01_b_o_o_s_t___p_p___i_t_e_r_a_t_i_o_n()_4.html#6ee3cb197b509a3776cf9da2a2c76c7f">rethrow</a> (boost::function&lt; void()&gt; onDestroyException)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_exception_expecter_3_01_e_00_01_b_o_o_s_t___p_p___i_t_e_r_a_t_i_o_n()_4.html#25d7ef75b058b698cc1e1c9c2040c781">free</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">releases any resources currently held by an <a class="el" href="class_exception_expecter.html">ExceptionExpecter</a> instance, and deletes the instance itself.  <a href="#25d7ef75b058b698cc1e1c9c2040c781"></a><br></td></tr>
<tr><td colspan="2"><br><h2>Static Private Member Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">static void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_exception_expecter_3_01_e_00_01_b_o_o_s_t___p_p___i_t_e_r_a_t_i_o_n()_4.html#8e196738b67d6243bb125990d5784fdb">throwExUnexpected</a> (boost::function&lt; void()&gt; &amp;onExceptionDestroyed)</td></tr>

<tr><td colspan="2"><br><h2>Private Attributes</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">boost::function&lt; void(details::CaughtExceptionType)&gt;&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_exception_expecter_3_01_e_00_01_b_o_o_s_t___p_p___i_t_e_r_a_t_i_o_n()_4.html#47c7e8f8aba1d42ee54c16817cc73835">m_onCompleteFunctor</a></td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">boost::function&lt; void(boost::function&lt;<br>
 void()&gt; &amp;)&gt;&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_exception_expecter_3_01_e_00_01_b_o_o_s_t___p_p___i_t_e_r_a_t_i_o_n()_4.html#219e9c28758614ab74b8be690eb426a8">m_rethrowFunctor</a></td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">details::CaughtExceptionType&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_exception_expecter_3_01_e_00_01_b_o_o_s_t___p_p___i_t_e_r_a_t_i_o_n()_4.html#00f35776d2ff698b8c635eb3aa34bc5a">m_caughtExceptionType</a></td></tr>

</table>
<h3>template&lt;typename E&gt;<br>
 class ExceptionExpecter&lt; E, BOOST_PP_ITERATION()&gt;</h3>

<hr><h2>Constructor &amp; Destructor Documentation</h2>
<a class="anchor" name="937fd96f92730d74258e35978f0325de"></a><!-- doxytag: member="ExceptionExpecter&lt; E, BOOST_PP_ITERATION()&gt;::ExceptionExpecter" ref="937fd96f92730d74258e35978f0325de" args="(boost::function&lt; void(details::CaughtExceptionType)&gt; onCompleteFunctor)" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename E&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="class_exception_expecter.html">ExceptionExpecter</a>&lt; E, BOOST_PP_ITERATION()&gt;::<a class="el" href="class_exception_expecter.html">ExceptionExpecter</a>           </td>
          <td>(</td>
          <td class="paramtype">boost::function&lt; void(details::CaughtExceptionType)&gt;&nbsp;</td>
          <td class="paramname"> <em>onCompleteFunctor</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"><code> [inline]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>

</div>
</div><p>
<a class="anchor" name="afb6f0922388eb72939bc6c78b755efb"></a><!-- doxytag: member="ExceptionExpecter&lt; E, BOOST_PP_ITERATION()&gt;::~ExceptionExpecter" ref="afb6f0922388eb72939bc6c78b755efb" args="()" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename E&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="class_exception_expecter.html">ExceptionExpecter</a>&lt; E, BOOST_PP_ITERATION()&gt;::~<a class="el" href="class_exception_expecter.html">ExceptionExpecter</a>           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"><code> [inline]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>

</div>
</div><p>
<hr><h2>Member Function Documentation</h2>
<a class="anchor" name="8344e702c16a56271d550db49f4d4b9f"></a><!-- doxytag: member="ExceptionExpecter&lt; E, BOOST_PP_ITERATION()&gt;::BOOST_PP_REPEAT_2ND" ref="8344e702c16a56271d550db49f4d4b9f" args="(BOOST_PP_ITERATION(), THROWEX, throwEx) void execute(boost" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename E&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="class_exception_expecter.html">ExceptionExpecter</a>&lt; E, BOOST_PP_ITERATION()&gt;::BOOST_PP_REPEAT_2ND           </td>
          <td>(</td>
          <td class="paramtype">BOOST_PP_ITERATION()&nbsp;</td>
          <td class="paramname">, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">THROWEX&nbsp;</td>
          <td class="paramname">, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">throwEx&nbsp;</td>
          <td class="paramname"></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td width="100%"><code> [inline]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>

</div>
</div><p>
<a class="anchor" name="6ee3cb197b509a3776cf9da2a2c76c7f"></a><!-- doxytag: member="ExceptionExpecter&lt; E, BOOST_PP_ITERATION()&gt;::rethrow" ref="6ee3cb197b509a3776cf9da2a2c76c7f" args="(boost::function&lt; void()&gt; onDestroyException)" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename E&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="class_exception_expecter.html">ExceptionExpecter</a>&lt; E, BOOST_PP_ITERATION()&gt;::rethrow           </td>
          <td>(</td>
          <td class="paramtype">boost::function&lt; void()&gt;&nbsp;</td>
          <td class="paramname"> <em>onDestroyException</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"><code> [inline]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>

</div>
</div><p>
<a class="anchor" name="25d7ef75b058b698cc1e1c9c2040c781"></a><!-- doxytag: member="ExceptionExpecter&lt; E, BOOST_PP_ITERATION()&gt;::free" ref="25d7ef75b058b698cc1e1c9c2040c781" args="()" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename E&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="class_exception_expecter.html">ExceptionExpecter</a>&lt; E, BOOST_PP_ITERATION()&gt;::free           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"><code> [inline]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
releases any resources currently held by an <a class="el" href="class_exception_expecter.html">ExceptionExpecter</a> instance, and deletes the instance itself. 
<p>

</div>
</div><p>
<a class="anchor" name="8e196738b67d6243bb125990d5784fdb"></a><!-- doxytag: member="ExceptionExpecter&lt; E, BOOST_PP_ITERATION()&gt;::throwExUnexpected" ref="8e196738b67d6243bb125990d5784fdb" args="(boost::function&lt; void()&gt; &amp;onExceptionDestroyed)" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename E&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname">static void <a class="el" href="class_exception_expecter.html">ExceptionExpecter</a>&lt; E, BOOST_PP_ITERATION()&gt;::throwExUnexpected           </td>
          <td>(</td>
          <td class="paramtype">boost::function&lt; void()&gt; &amp;&nbsp;</td>
          <td class="paramname"> <em>onExceptionDestroyed</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"><code> [inline, static, private]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>

</div>
</div><p>
<hr><h2>Member Data Documentation</h2>
<a class="anchor" name="47c7e8f8aba1d42ee54c16817cc73835"></a><!-- doxytag: member="ExceptionExpecter&lt; E, BOOST_PP_ITERATION()&gt;::m_onCompleteFunctor" ref="47c7e8f8aba1d42ee54c16817cc73835" args="" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename E&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname">boost::function&lt;void(details::CaughtExceptionType)&gt; <a class="el" href="class_exception_expecter.html">ExceptionExpecter</a>&lt; E, BOOST_PP_ITERATION()&gt;::<a class="el" href="class_exception_expecter_3_01_e_00_01_b_o_o_s_t___p_p___i_t_e_r_a_t_i_o_n()_4.html#47c7e8f8aba1d42ee54c16817cc73835">m_onCompleteFunctor</a><code> [private]</code>          </td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>

</div>
</div><p>
<a class="anchor" name="219e9c28758614ab74b8be690eb426a8"></a><!-- doxytag: member="ExceptionExpecter&lt; E, BOOST_PP_ITERATION()&gt;::m_rethrowFunctor" ref="219e9c28758614ab74b8be690eb426a8" args="" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename E&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname">boost::function&lt;void(boost::function&lt;void()&gt;&amp;)&gt; <a class="el" href="class_exception_expecter.html">ExceptionExpecter</a>&lt; E, BOOST_PP_ITERATION()&gt;::<a class="el" href="class_exception_expecter_3_01_e_00_01_b_o_o_s_t___p_p___i_t_e_r_a_t_i_o_n()_4.html#219e9c28758614ab74b8be690eb426a8">m_rethrowFunctor</a><code> [private]</code>          </td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>

</div>
</div><p>
<a class="anchor" name="00f35776d2ff698b8c635eb3aa34bc5a"></a><!-- doxytag: member="ExceptionExpecter&lt; E, BOOST_PP_ITERATION()&gt;::m_caughtExceptionType" ref="00f35776d2ff698b8c635eb3aa34bc5a" args="" -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename E&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname">details::CaughtExceptionType <a class="el" href="class_exception_expecter.html">ExceptionExpecter</a>&lt; E, BOOST_PP_ITERATION()&gt;::<a class="el" href="class_exception_expecter_3_01_e_00_01_b_o_o_s_t___p_p___i_t_e_r_a_t_i_o_n()_4.html#00f35776d2ff698b8c635eb3aa34bc5a">m_caughtExceptionType</a><code> [private]</code>          </td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>

</div>
</div><p>
<hr>The documentation for this class was generated from the following file:<ul>
<li>ThreadSynch/<a class="el" href="_exception_expecter__template_8h.html">ExceptionExpecter_template.h</a></ul>
<hr size="1"><address style="align: right;"><small>Generated on Tue Mar 13 23:06:20 2007 for ThreadSynch by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.1-p1 </small></address>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


Written By
Software Developer
Norway Norway
My name is Einar Otto Stangvik, and I'm a programmer based in Oslo, Norway. I mainly develop applications and software architectures targetting C++ on the Windows platform, but I have also got experience doing the same on Unix and Linux. The last few years I've used C# a lot, but native C++ is still my main focus.


As of July 2008, I'm a Microsoft MVP for Visual C++.


Follow me on Twitter: @einaros
My code blog: einaros.blogspot.com
My site: www.indev.no

Comments and Discussions