<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<doxygen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="compound.xsd" version="1.8.14">
  <compounddef id="ctpl_8h" kind="file" language="C++">
    <compoundname>ctpl.h</compoundname>
    <includes refid="global_8h" local="yes">../../global.h</includes>
    <includes local="no">atomic</includes>
    <includes local="no">exception</includes>
    <includes local="no">functional</includes>
    <includes local="no">future</includes>
    <includes local="no">memory</includes>
    <includes local="no">mutex</includes>
    <includes local="no">queue</includes>
    <includes local="no">thread</includes>
    <includes local="no">vector</includes>
    <includes refid="types_8h" local="yes">../../types.h</includes>
    <includes refid="desk_8h" local="yes">../desk.h</includes>
    <includedby refid="forest_8h" local="yes">/Users/classner/git/forpy/include/forpy/forest.h</includedby>
    <incdepgraph>
      <node id="1391">
        <label>atomic</label>
      </node>
      <node id="1393">
        <label>functional</label>
      </node>
      <node id="1385">
        <label>iomanip</label>
      </node>
      <node id="1397">
        <label>queue</label>
      </node>
      <node id="1407">
        <label>mapbox/variant_cast.hpp</label>
      </node>
      <node id="1384">
        <label>glog/logging.h</label>
      </node>
      <node id="1402">
        <label>numeric</label>
      </node>
      <node id="1389">
        <label>string</label>
      </node>
      <node id="1388">
        <label>./version.h</label>
        <link refid="version_8h"/>
      </node>
      <node id="1401">
        <label>map</label>
      </node>
      <node id="1409">
        <label>../desk.h</label>
        <link refid="desk_8h"/>
        <childnode refid="1383" relation="include">
        </childnode>
        <childnode refid="1399" relation="include">
        </childnode>
      </node>
      <node id="1392">
        <label>exception</label>
      </node>
      <node id="1404">
        <label>./util/hash.h</label>
        <link refid="hash_8h"/>
        <childnode refid="1405" relation="include">
        </childnode>
        <childnode refid="1398" relation="include">
        </childnode>
      </node>
      <node id="1400">
        <label>Eigen/Dense</label>
      </node>
      <node id="1394">
        <label>future</label>
      </node>
      <node id="1406">
        <label>./util/storage.h</label>
        <link refid="storage_8h"/>
        <childnode refid="1407" relation="include">
        </childnode>
        <childnode refid="1408" relation="include">
        </childnode>
      </node>
      <node id="1398">
        <label>vector</label>
      </node>
      <node id="1403">
        <label>utility</label>
      </node>
      <node id="1386">
        <label>iostream</label>
      </node>
      <node id="1383">
        <label>../../global.h</label>
        <link refid="global_8h"/>
        <childnode refid="1384" relation="include">
        </childnode>
        <childnode refid="1385" relation="include">
        </childnode>
        <childnode refid="1386" relation="include">
        </childnode>
        <childnode refid="1387" relation="include">
        </childnode>
        <childnode refid="1388" relation="include">
        </childnode>
        <childnode refid="1389" relation="include">
        </childnode>
        <childnode refid="1390" relation="include">
        </childnode>
      </node>
      <node id="1405">
        <label>cstddef</label>
      </node>
      <node id="1396">
        <label>mutex</label>
      </node>
      <node id="1390">
        <label>csignal</label>
      </node>
      <node id="1387">
        <label>thread</label>
      </node>
      <node id="1399">
        <label>../../types.h</label>
        <link refid="types_8h"/>
        <childnode refid="1400" relation="include">
        </childnode>
        <childnode refid="1401" relation="include">
        </childnode>
        <childnode refid="1395" relation="include">
        </childnode>
        <childnode refid="1402" relation="include">
        </childnode>
        <childnode refid="1403" relation="include">
        </childnode>
        <childnode refid="1398" relation="include">
        </childnode>
        <childnode refid="1404" relation="include">
        </childnode>
        <childnode refid="1406" relation="include">
        </childnode>
      </node>
      <node id="1408">
        <label>./serialization/variant.h</label>
      </node>
      <node id="1382">
        <label>/Users/classner/git/forpy/include/forpy/util/threading/ctpl.h</label>
        <link refid="ctpl_8h"/>
        <childnode refid="1383" relation="include">
        </childnode>
        <childnode refid="1391" relation="include">
        </childnode>
        <childnode refid="1392" relation="include">
        </childnode>
        <childnode refid="1393" relation="include">
        </childnode>
        <childnode refid="1394" relation="include">
        </childnode>
        <childnode refid="1395" relation="include">
        </childnode>
        <childnode refid="1396" relation="include">
        </childnode>
        <childnode refid="1397" relation="include">
        </childnode>
        <childnode refid="1387" relation="include">
        </childnode>
        <childnode refid="1398" relation="include">
        </childnode>
        <childnode refid="1399" relation="include">
        </childnode>
        <childnode refid="1409" relation="include">
        </childnode>
      </node>
      <node id="1395">
        <label>memory</label>
      </node>
    </incdepgraph>
    <invincdepgraph>
      <node id="1412">
        <label>/Users/classner/git/forpy/include/forpy/forpy.h</label>
        <link refid="forpy_8h"/>
      </node>
      <node id="1411">
        <label>/Users/classner/git/forpy/include/forpy/forest.h</label>
        <link refid="forest_8h"/>
        <childnode refid="1412" relation="include">
        </childnode>
      </node>
      <node id="1410">
        <label>/Users/classner/git/forpy/include/forpy/util/threading/ctpl.h</label>
        <link refid="ctpl_8h"/>
        <childnode refid="1411" relation="include">
        </childnode>
      </node>
    </invincdepgraph>
    <innerclass refid="classforpy_1_1threading_1_1detail_1_1_queue" prot="public">forpy::threading::detail::Queue</innerclass>
    <innerclass refid="classforpy_1_1threading_1_1thread__pool" prot="public">forpy::threading::thread_pool</innerclass>
    <innerclass refid="classforpy_1_1_thread_control" prot="public">forpy::ThreadControl</innerclass>
    <innernamespace refid="namespaceforpy">forpy</innernamespace>
    <innernamespace refid="namespaceforpy_1_1threading">forpy::threading</innernamespace>
    <innernamespace refid="namespaceforpy_1_1threading_1_1detail">forpy::threading::detail</innernamespace>
    <briefdescription>
    </briefdescription>
    <detaileddescription>
    </detaileddescription>
    <programlisting>
<codeline lineno="1"><highlight class="comment">//<sp/>This<sp/>is<sp/>an<sp/>adapted<sp/>version<sp/>of<sp/>the<sp/>excellent<sp/>CTPL<sp/>library</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="2"><highlight class="normal"></highlight><highlight class="comment">//<sp/>(https://raw.githubusercontent.com/vit-vit/CTPL/master/ctpl_stl.h).<sp/>The</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="3"><highlight class="normal"></highlight><highlight class="comment">//<sp/>original<sp/>copyright<sp/>notice<sp/>from<sp/>Vitaliy<sp/>Vitsentiy<sp/>can<sp/>be<sp/>found<sp/>below.<sp/>There</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="4"><highlight class="normal"></highlight><highlight class="comment">//<sp/>have<sp/>been<sp/>minor<sp/>changes<sp/>to<sp/>the<sp/>file<sp/>for<sp/>the<sp/>use<sp/>with<sp/>forpy.</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="5"><highlight class="normal"></highlight></codeline>
<codeline lineno="6"><highlight class="normal"></highlight><highlight class="comment">/*********************************************************</highlight></codeline>
<codeline lineno="7"><highlight class="comment"><sp/>*</highlight></codeline>
<codeline lineno="8"><highlight class="comment"><sp/>*<sp/><sp/>Copyright<sp/>(C)<sp/>2014<sp/>by<sp/>Vitaliy<sp/>Vitsentiy</highlight></codeline>
<codeline lineno="9"><highlight class="comment"><sp/>*</highlight></codeline>
<codeline lineno="10"><highlight class="comment"><sp/>*<sp/><sp/>Licensed<sp/>under<sp/>the<sp/>Apache<sp/>License,<sp/>Version<sp/>2.0<sp/>(the<sp/>&quot;License&quot;);</highlight></codeline>
<codeline lineno="11"><highlight class="comment"><sp/>*<sp/><sp/>you<sp/>may<sp/>not<sp/>use<sp/>this<sp/>file<sp/>except<sp/>in<sp/>compliance<sp/>with<sp/>the<sp/>License.</highlight></codeline>
<codeline lineno="12"><highlight class="comment"><sp/>*<sp/><sp/>You<sp/>may<sp/>obtain<sp/>a<sp/>copy<sp/>of<sp/>the<sp/>License<sp/>at</highlight></codeline>
<codeline lineno="13"><highlight class="comment"><sp/>*</highlight></codeline>
<codeline lineno="14"><highlight class="comment"><sp/>*<sp/><sp/><sp/><sp/><sp/>http://www.apache.org/licenses/LICENSE-2.0</highlight></codeline>
<codeline lineno="15"><highlight class="comment"><sp/>*</highlight></codeline>
<codeline lineno="16"><highlight class="comment"><sp/>*<sp/><sp/>Unless<sp/>required<sp/>by<sp/>applicable<sp/>law<sp/>or<sp/>agreed<sp/>to<sp/>in<sp/>writing,<sp/>software</highlight></codeline>
<codeline lineno="17"><highlight class="comment"><sp/>*<sp/><sp/>distributed<sp/>under<sp/>the<sp/>License<sp/>is<sp/>distributed<sp/>on<sp/>an<sp/>&quot;AS<sp/>IS&quot;<sp/>BASIS,</highlight></codeline>
<codeline lineno="18"><highlight class="comment"><sp/>*<sp/><sp/>WITHOUT<sp/>WARRANTIES<sp/>OR<sp/>CONDITIONS<sp/>OF<sp/>ANY<sp/>KIND,<sp/>either<sp/>express<sp/>or<sp/>implied.</highlight></codeline>
<codeline lineno="19"><highlight class="comment"><sp/>*<sp/><sp/>See<sp/>the<sp/>License<sp/>for<sp/>the<sp/>specific<sp/>language<sp/>governing<sp/>permissions<sp/>and</highlight></codeline>
<codeline lineno="20"><highlight class="comment"><sp/>*<sp/><sp/>limitations<sp/>under<sp/>the<sp/>License.</highlight></codeline>
<codeline lineno="21"><highlight class="comment"><sp/>*</highlight></codeline>
<codeline lineno="22"><highlight class="comment"><sp/>*********************************************************/</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="23"><highlight class="normal"></highlight></codeline>
<codeline lineno="24"><highlight class="normal"></highlight><highlight class="preprocessor">#ifndef<sp/>FORPY_UTIL_THREADING_CTPL_H_</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="25"><highlight class="normal"></highlight><highlight class="preprocessor">#define<sp/>FORPY_UTIL_THREADING_CTPL_H_</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="26"><highlight class="normal"></highlight></codeline>
<codeline lineno="27"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>&quot;../../global.h&quot;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="28"><highlight class="normal"></highlight></codeline>
<codeline lineno="29"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>&lt;atomic&gt;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="30"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>&lt;exception&gt;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="31"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>&lt;functional&gt;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="32"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>&lt;future&gt;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="33"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>&lt;memory&gt;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="34"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>&lt;mutex&gt;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="35"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>&lt;queue&gt;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="36"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>&lt;thread&gt;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="37"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>&lt;vector&gt;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="38"><highlight class="normal"></highlight></codeline>
<codeline lineno="39"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>&quot;../../types.h&quot;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="40"><highlight class="normal"></highlight><highlight class="preprocessor">#include<sp/>&quot;../desk.h&quot;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="41"><highlight class="normal"></highlight></codeline>
<codeline lineno="42"><highlight class="normal"></highlight><highlight class="keyword">namespace<sp/></highlight><highlight class="normal"><ref refid="namespaceforpy" kindref="compound">forpy</ref><sp/>{</highlight></codeline>
<codeline lineno="43" refid="namespaceforpy_1_1threading" refkind="compound"><highlight class="normal"></highlight><highlight class="keyword">namespace<sp/></highlight><highlight class="normal">threading<sp/>{</highlight></codeline>
<codeline lineno="44"><highlight class="normal"></highlight></codeline>
<codeline lineno="45" refid="namespaceforpy_1_1threading_1a0454f9ca919afa1f786f40abecbc0ffc" refkind="member"><highlight class="normal"></highlight><highlight class="keyword">typedef</highlight><highlight class="normal"><sp/><ref refid="structforpy_1_1_desk" kindref="compound">forpy::Desk</ref><sp/>*<ref refid="namespaceforpy_1_1threading_1a0454f9ca919afa1f786f40abecbc0ffc" kindref="member">INFOT</ref>;</highlight></codeline>
<codeline lineno="46"><highlight class="normal"></highlight></codeline>
<codeline lineno="47" refid="namespaceforpy_1_1threading_1_1detail" refkind="compound"><highlight class="normal"></highlight><highlight class="keyword">namespace<sp/></highlight><highlight class="normal">detail<sp/>{</highlight></codeline>
<codeline lineno="48"><highlight class="normal"></highlight><highlight class="keyword">template</highlight><highlight class="normal"><sp/>&lt;</highlight><highlight class="keyword">typename</highlight><highlight class="normal"><sp/>T&gt;</highlight></codeline>
<codeline lineno="49" refid="classforpy_1_1threading_1_1detail_1_1_queue" refkind="compound"><highlight class="normal"></highlight><highlight class="keyword">class<sp/></highlight><highlight class="normal"><ref refid="classforpy_1_1threading_1_1detail_1_1_queue" kindref="compound">Queue</ref><sp/>{</highlight></codeline>
<codeline lineno="50"><highlight class="normal"><sp/></highlight><highlight class="keyword">public</highlight><highlight class="normal">:</highlight></codeline>
<codeline lineno="51" refid="classforpy_1_1threading_1_1detail_1_1_queue_1acfd4ff280460de88488c7af85b2440c2" refkind="member"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">bool</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1threading_1_1detail_1_1_queue_1acfd4ff280460de88488c7af85b2440c2" kindref="member">push</ref>(T<sp/></highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/>&amp;value)<sp/>{</highlight></codeline>
<codeline lineno="52"><highlight class="normal"><sp/><sp/><sp/><sp/>std::unique_lock&lt;std::mutex&gt;<sp/>lock(this-&gt;<ref refid="classforpy_1_1threading_1_1detail_1_1_queue_1ac41d1cdff98d3f5c262770bba20a8ae8" kindref="member">mutex</ref>);</highlight></codeline>
<codeline lineno="53"><highlight class="normal"><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1detail_1_1_queue_1a4821f7df32a2c8e9de20d201a9921fdd" kindref="member">q</ref>.push(value);</highlight></codeline>
<codeline lineno="54"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/></highlight><highlight class="keyword">true</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="55"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="56"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>deletes<sp/>the<sp/>retrieved<sp/>element,<sp/>do<sp/>not<sp/>use<sp/>for<sp/>non<sp/>integral<sp/>types</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="57" refid="classforpy_1_1threading_1_1detail_1_1_queue_1adda1fc21d4f34851fe89eaf9475d04a2" refkind="member"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">bool</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1threading_1_1detail_1_1_queue_1adda1fc21d4f34851fe89eaf9475d04a2" kindref="member">pop</ref>(T<sp/>&amp;v)<sp/>{</highlight></codeline>
<codeline lineno="58"><highlight class="normal"><sp/><sp/><sp/><sp/>std::unique_lock&lt;std::mutex&gt;<sp/>lock(this-&gt;<ref refid="classforpy_1_1threading_1_1detail_1_1_queue_1ac41d1cdff98d3f5c262770bba20a8ae8" kindref="member">mutex</ref>);</highlight></codeline>
<codeline lineno="59"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(this-&gt;<ref refid="classforpy_1_1threading_1_1detail_1_1_queue_1a4821f7df32a2c8e9de20d201a9921fdd" kindref="member">q</ref>.empty())<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/></highlight><highlight class="keyword">false</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="60"><highlight class="normal"><sp/><sp/><sp/><sp/>v<sp/>=<sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1detail_1_1_queue_1a4821f7df32a2c8e9de20d201a9921fdd" kindref="member">q</ref>.front();</highlight></codeline>
<codeline lineno="61"><highlight class="normal"><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1detail_1_1_queue_1a4821f7df32a2c8e9de20d201a9921fdd" kindref="member">q</ref>.pop();</highlight></codeline>
<codeline lineno="62"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/></highlight><highlight class="keyword">true</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="63"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="64" refid="classforpy_1_1threading_1_1detail_1_1_queue_1a96c9a7be2f5fc97e59d991073e30ae33" refkind="member"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">bool</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1threading_1_1detail_1_1_queue_1a96c9a7be2f5fc97e59d991073e30ae33" kindref="member">empty</ref>()<sp/>{</highlight></codeline>
<codeline lineno="65"><highlight class="normal"><sp/><sp/><sp/><sp/>std::unique_lock&lt;std::mutex&gt;<sp/>lock(this-&gt;<ref refid="classforpy_1_1threading_1_1detail_1_1_queue_1ac41d1cdff98d3f5c262770bba20a8ae8" kindref="member">mutex</ref>);</highlight></codeline>
<codeline lineno="66"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1detail_1_1_queue_1a4821f7df32a2c8e9de20d201a9921fdd" kindref="member">q</ref>.empty();</highlight></codeline>
<codeline lineno="67"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="68"><highlight class="normal"></highlight></codeline>
<codeline lineno="69"><highlight class="normal"><sp/></highlight><highlight class="keyword">private</highlight><highlight class="normal">:</highlight></codeline>
<codeline lineno="70" refid="classforpy_1_1threading_1_1detail_1_1_queue_1a4821f7df32a2c8e9de20d201a9921fdd" refkind="member"><highlight class="normal"><sp/><sp/>std::queue&lt;T&gt;<sp/><ref refid="classforpy_1_1threading_1_1detail_1_1_queue_1a4821f7df32a2c8e9de20d201a9921fdd" kindref="member">q</ref>;</highlight></codeline>
<codeline lineno="71" refid="classforpy_1_1threading_1_1detail_1_1_queue_1ac41d1cdff98d3f5c262770bba20a8ae8" refkind="member"><highlight class="normal"><sp/><sp/>std::mutex<sp/><ref refid="classforpy_1_1threading_1_1detail_1_1_queue_1ac41d1cdff98d3f5c262770bba20a8ae8" kindref="member">mutex</ref>;</highlight></codeline>
<codeline lineno="72"><highlight class="normal">};</highlight></codeline>
<codeline lineno="73"><highlight class="normal">}<sp/><sp/></highlight><highlight class="comment">//<sp/>namespace<sp/>detail</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="74"><highlight class="normal"></highlight></codeline>
<codeline lineno="75" refid="classforpy_1_1threading_1_1thread__pool" refkind="compound"><highlight class="normal"></highlight><highlight class="keyword">class<sp/></highlight><highlight class="normal"><ref refid="classforpy_1_1threading_1_1thread__pool" kindref="compound">thread_pool</ref><sp/>{</highlight></codeline>
<codeline lineno="76"><highlight class="normal"><sp/></highlight><highlight class="keyword">public</highlight><highlight class="normal">:</highlight></codeline>
<codeline lineno="77" refid="classforpy_1_1threading_1_1thread__pool_1a60bf54202abc186b165f123df1bd24cf" refkind="member"><highlight class="normal"><sp/><sp/><ref refid="classforpy_1_1threading_1_1thread__pool_1a60bf54202abc186b165f123df1bd24cf" kindref="member">thread_pool</ref>()<sp/>{<sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a28759c9a177e27fa6488457e36edf971" kindref="member">init</ref>();<sp/>}</highlight></codeline>
<codeline lineno="78" refid="classforpy_1_1threading_1_1thread__pool_1a273c87ddac976418f06543a058237963" refkind="member"><highlight class="normal"><sp/><sp/><ref refid="classforpy_1_1threading_1_1thread__pool_1a273c87ddac976418f06543a058237963" kindref="member">thread_pool</ref>(</highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>nThreads)<sp/>{</highlight></codeline>
<codeline lineno="79"><highlight class="normal"><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a28759c9a177e27fa6488457e36edf971" kindref="member">init</ref>();</highlight></codeline>
<codeline lineno="80"><highlight class="normal"><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a7b5bf432e02e622a42afb66d64b60f58" kindref="member">resize</ref>(nThreads);</highlight></codeline>
<codeline lineno="81"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="82"><highlight class="normal"></highlight></codeline>
<codeline lineno="83"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>the<sp/>destructor<sp/>waits<sp/>for<sp/>all<sp/>the<sp/>functions<sp/>in<sp/>the<sp/>queue<sp/>to<sp/>be<sp/>finished</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="84" refid="classforpy_1_1threading_1_1thread__pool_1aa7f143dcfeda39ca126c1bf73e265f97" refkind="member"><highlight class="normal"><sp/><sp/><ref refid="classforpy_1_1threading_1_1thread__pool_1aa7f143dcfeda39ca126c1bf73e265f97" kindref="member">~thread_pool</ref>()<sp/>{<sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a8e28d17519bb25272573aa38abadddc9" kindref="member">stop</ref>(</highlight><highlight class="keyword">true</highlight><highlight class="normal">);<sp/>}</highlight></codeline>
<codeline lineno="85"><highlight class="normal"></highlight></codeline>
<codeline lineno="86"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>get<sp/>the<sp/>number<sp/>of<sp/>running<sp/>threads<sp/>in<sp/>the<sp/>pool</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="87" refid="classforpy_1_1threading_1_1thread__pool_1a3b1566564662f2c4c63e61ae0b0777c9" refkind="member"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1threading_1_1thread__pool_1a3b1566564662f2c4c63e61ae0b0777c9" kindref="member">size</ref>()<sp/>{<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/></highlight><highlight class="keyword">static_cast&lt;</highlight><highlight class="keywordtype">int</highlight><highlight class="keyword">&gt;</highlight><highlight class="normal">(this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a7f58d36428162c1e2b375113bd00151e" kindref="member">threads</ref>.size());<sp/>}</highlight></codeline>
<codeline lineno="88"><highlight class="normal"></highlight></codeline>
<codeline lineno="89"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>number<sp/>of<sp/>idle<sp/>threads</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="90" refid="classforpy_1_1threading_1_1thread__pool_1a0919c3ea2ff9f195ef73804efb2a5869" refkind="member"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1threading_1_1thread__pool_1a0919c3ea2ff9f195ef73804efb2a5869" kindref="member">n_idle</ref>()<sp/>{<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a2441eb7bc713bc66c89532a721f6cb19" kindref="member">nWaiting</ref>;<sp/>}</highlight></codeline>
<codeline lineno="91" refid="classforpy_1_1threading_1_1thread__pool_1aa00f49e3b64e9285634ffd1e0d9cd4c2" refkind="member"><highlight class="normal"><sp/><sp/>std::thread<sp/>&amp;<ref refid="classforpy_1_1threading_1_1thread__pool_1aa00f49e3b64e9285634ffd1e0d9cd4c2" kindref="member">get_thread</ref>(</highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>i)<sp/>{<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>*this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a7f58d36428162c1e2b375113bd00151e" kindref="member">threads</ref>[i];<sp/>}</highlight></codeline>
<codeline lineno="92"><highlight class="normal"></highlight></codeline>
<codeline lineno="93"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>change<sp/>the<sp/>number<sp/>of<sp/>threads<sp/>in<sp/>the<sp/>pool</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="94"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>should<sp/>be<sp/>called<sp/>from<sp/>one<sp/>thread,<sp/>otherwise<sp/>be<sp/>careful<sp/>to<sp/>not<sp/>interleave,</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="95"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>also<sp/>with<sp/>this-&gt;stop()</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="96"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>nThreads<sp/>must<sp/>be<sp/>&gt;=<sp/>0</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="97" refid="classforpy_1_1threading_1_1thread__pool_1a7b5bf432e02e622a42afb66d64b60f58" refkind="member"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1threading_1_1thread__pool_1a7b5bf432e02e622a42afb66d64b60f58" kindref="member">resize</ref>(</highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>nThreads)<sp/>{</highlight></codeline>
<codeline lineno="98"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1ad54e73503f80bb369ef816c979d5263e" kindref="member">isStop</ref><sp/>&amp;&amp;<sp/>!this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1ab875f9f5d7cf0f773d8682bec5986a78" kindref="member">isDone</ref>)<sp/>{</highlight></codeline>
<codeline lineno="99"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>oldNThreads<sp/>=<sp/></highlight><highlight class="keyword">static_cast&lt;</highlight><highlight class="keywordtype">int</highlight><highlight class="keyword">&gt;</highlight><highlight class="normal">(this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a7f58d36428162c1e2b375113bd00151e" kindref="member">threads</ref>.size());</highlight></codeline>
<codeline lineno="100"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(oldNThreads<sp/>&lt;=<sp/>nThreads)<sp/>{<sp/><sp/></highlight><highlight class="comment">//<sp/>if<sp/>the<sp/>number<sp/>of<sp/>threads<sp/>is<sp/>increased</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="101"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a7f58d36428162c1e2b375113bd00151e" kindref="member">threads</ref>.resize(nThreads);</highlight></codeline>
<codeline lineno="102"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a9307094feb4d1f01ff0a651448f81a80" kindref="member">flags</ref>.resize(nThreads);</highlight></codeline>
<codeline lineno="103"><highlight class="normal"></highlight></codeline>
<codeline lineno="104"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">for</highlight><highlight class="normal"><sp/>(</highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>i<sp/>=<sp/>oldNThreads;<sp/>i<sp/>&lt;<sp/>nThreads;<sp/>++i)<sp/>{</highlight></codeline>
<codeline lineno="105"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a9307094feb4d1f01ff0a651448f81a80" kindref="member">flags</ref>[i]<sp/>=<sp/>std::make_shared&lt;std::atomic&lt;bool&gt;&gt;(</highlight><highlight class="keyword">false</highlight><highlight class="normal">);</highlight></codeline>
<codeline lineno="106"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a6b4c6c47566081aedf7c6e6400aa9a87" kindref="member">set_thread</ref>(i);</highlight></codeline>
<codeline lineno="107"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="108"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>}<sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"><sp/>{<sp/><sp/></highlight><highlight class="comment">//<sp/>the<sp/>number<sp/>of<sp/>threads<sp/>is<sp/>decreased</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="109"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">for</highlight><highlight class="normal"><sp/>(</highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>i<sp/>=<sp/>oldNThreads<sp/>-<sp/>1;<sp/>i<sp/>&gt;=<sp/>nThreads;<sp/>--i)<sp/>{</highlight></codeline>
<codeline lineno="110"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>*this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a9307094feb4d1f01ff0a651448f81a80" kindref="member">flags</ref>[i]<sp/>=<sp/></highlight><highlight class="keyword">true</highlight><highlight class="normal">;<sp/><sp/></highlight><highlight class="comment">//<sp/>this<sp/>thread<sp/>will<sp/>finish</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="111"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a7f58d36428162c1e2b375113bd00151e" kindref="member">threads</ref>[i]-&gt;detach();</highlight></codeline>
<codeline lineno="112"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="113"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>{</highlight></codeline>
<codeline lineno="114"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>stop<sp/>the<sp/>detached<sp/>threads<sp/>that<sp/>were<sp/>waiting</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="115"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>std::unique_lock&lt;std::mutex&gt;<sp/>lock(this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a8f6ad65d996d5b6c7c62e1990b780680" kindref="member">mutex</ref>);</highlight></codeline>
<codeline lineno="116"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a62003c15c75795b96a1144ab9542ff23" kindref="member">cv</ref>.notify_all();</highlight></codeline>
<codeline lineno="117"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="118"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a7f58d36428162c1e2b375113bd00151e" kindref="member">threads</ref>.resize(</highlight></codeline>
<codeline lineno="119"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>nThreads);<sp/><sp/></highlight><highlight class="comment">//<sp/>safe<sp/>to<sp/>delete<sp/>because<sp/>the<sp/>threads<sp/>are<sp/>detached</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="120"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a9307094feb4d1f01ff0a651448f81a80" kindref="member">flags</ref>.resize(nThreads);<sp/><sp/></highlight><highlight class="comment">//<sp/>safe<sp/>to<sp/>delete<sp/>because<sp/>the<sp/>threads</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="121"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>have<sp/>copies<sp/>of<sp/>shared_ptr<sp/>of<sp/>the</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="122"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>flags,<sp/>not<sp/>originals</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="123"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="124"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="125"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="126"><highlight class="normal"></highlight></codeline>
<codeline lineno="127"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>empty<sp/>the<sp/>queue</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="128" refid="classforpy_1_1threading_1_1thread__pool_1aa0c16c2b18e42bfdd7ae9591b8e14ecd" refkind="member"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1threading_1_1thread__pool_1aa0c16c2b18e42bfdd7ae9591b8e14ecd" kindref="member">clear_queue</ref>()<sp/>{</highlight></codeline>
<codeline lineno="129"><highlight class="normal"><sp/><sp/><sp/><sp/>std::function&lt;void(INFOT)&gt;<sp/>*_f;</highlight></codeline>
<codeline lineno="130"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">while</highlight><highlight class="normal"><sp/>(this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a82bf22c7fe0eab4da78ea3b4eb1dd6b1" kindref="member">q</ref>.pop(_f))<sp/></highlight><highlight class="keyword">delete</highlight><highlight class="normal"><sp/>_f;<sp/><sp/></highlight><highlight class="comment">//<sp/>empty<sp/>the<sp/>queue</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="131"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="132"><highlight class="normal"></highlight></codeline>
<codeline lineno="133"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>pops<sp/>a<sp/>functional<sp/>wrapper<sp/>to<sp/>the<sp/>original<sp/>function</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="134" refid="classforpy_1_1threading_1_1thread__pool_1a80c7b60bd2557200cb269ec9fd33b54a" refkind="member"><highlight class="normal"><sp/><sp/>std::function&lt;void(INFOT)&gt;<sp/><ref refid="classforpy_1_1threading_1_1thread__pool_1a80c7b60bd2557200cb269ec9fd33b54a" kindref="member">pop</ref>()<sp/>{</highlight></codeline>
<codeline lineno="135"><highlight class="normal"><sp/><sp/><sp/><sp/>std::function&lt;void(INFOT)&gt;<sp/>*_f<sp/>=<sp/></highlight><highlight class="keyword">nullptr</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="136"><highlight class="normal"><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a82bf22c7fe0eab4da78ea3b4eb1dd6b1" kindref="member">q</ref>.pop(_f);</highlight></codeline>
<codeline lineno="137"><highlight class="normal"><sp/><sp/><sp/><sp/>std::unique_ptr&lt;std::function&lt;void(INFOT)&gt;&gt;<sp/>func(</highlight></codeline>
<codeline lineno="138"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>_f);<sp/><sp/></highlight><highlight class="comment">//<sp/>at<sp/>return,<sp/>delete<sp/>the<sp/>function<sp/>even<sp/>if<sp/>an<sp/>exception<sp/>occurred</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="139"><highlight class="normal"><sp/><sp/><sp/><sp/>std::function&lt;void(INFOT)&gt;<sp/>f;</highlight></codeline>
<codeline lineno="140"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(_f)<sp/>f<sp/>=<sp/>*_f;</highlight></codeline>
<codeline lineno="141"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>f;</highlight></codeline>
<codeline lineno="142"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="143"><highlight class="normal"></highlight></codeline>
<codeline lineno="144"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>wait<sp/>for<sp/>all<sp/>computing<sp/>threads<sp/>to<sp/>finish<sp/>and<sp/>stop<sp/>all<sp/>threads</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="145"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>may<sp/>be<sp/>called<sp/>asynchronously<sp/>to<sp/>not<sp/>pause<sp/>the<sp/>calling<sp/>thread<sp/>while<sp/>waiting</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="146"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>if<sp/>isWait<sp/>==<sp/>true,<sp/>all<sp/>the<sp/>functions<sp/>in<sp/>the<sp/>queue<sp/>are<sp/>run,<sp/>otherwise<sp/>the</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="147"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>queue<sp/>is<sp/>cleared<sp/>without<sp/>running<sp/>the<sp/>functions</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="148" refid="classforpy_1_1threading_1_1thread__pool_1a8e28d17519bb25272573aa38abadddc9" refkind="member"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1threading_1_1thread__pool_1a8e28d17519bb25272573aa38abadddc9" kindref="member">stop</ref>(</highlight><highlight class="keywordtype">bool</highlight><highlight class="normal"><sp/>isWait<sp/>=<sp/></highlight><highlight class="keyword">false</highlight><highlight class="normal">)<sp/>{</highlight></codeline>
<codeline lineno="149"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!isWait)<sp/>{</highlight></codeline>
<codeline lineno="150"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1ad54e73503f80bb369ef816c979d5263e" kindref="member">isStop</ref>)<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="151"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1ad54e73503f80bb369ef816c979d5263e" kindref="member">isStop</ref><sp/>=<sp/></highlight><highlight class="keyword">true</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="152"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">for</highlight><highlight class="normal"><sp/>(</highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>i<sp/>=<sp/>0,<sp/>n<sp/>=<sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a3b1566564662f2c4c63e61ae0b0777c9" kindref="member">size</ref>();<sp/>i<sp/>&lt;<sp/>n;<sp/>++i)<sp/>{</highlight></codeline>
<codeline lineno="153"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>*this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a9307094feb4d1f01ff0a651448f81a80" kindref="member">flags</ref>[i]<sp/>=<sp/></highlight><highlight class="keyword">true</highlight><highlight class="normal">;<sp/><sp/></highlight><highlight class="comment">//<sp/>command<sp/>the<sp/>threads<sp/>to<sp/>stop</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="154"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="155"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1aa0c16c2b18e42bfdd7ae9591b8e14ecd" kindref="member">clear_queue</ref>();<sp/><sp/></highlight><highlight class="comment">//<sp/>empty<sp/>the<sp/>queue</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="156"><highlight class="normal"><sp/><sp/><sp/><sp/>}<sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"><sp/>{</highlight></codeline>
<codeline lineno="157"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1ab875f9f5d7cf0f773d8682bec5986a78" kindref="member">isDone</ref><sp/>||<sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1ad54e73503f80bb369ef816c979d5263e" kindref="member">isStop</ref>)<sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="158"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1ab875f9f5d7cf0f773d8682bec5986a78" kindref="member">isDone</ref><sp/>=<sp/></highlight><highlight class="keyword">true</highlight><highlight class="normal">;<sp/><sp/></highlight><highlight class="comment">//<sp/>give<sp/>the<sp/>waiting<sp/>threads<sp/>a<sp/>command<sp/>to<sp/>finish</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="159"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="160"><highlight class="normal"><sp/><sp/><sp/><sp/>{</highlight></codeline>
<codeline lineno="161"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>std::unique_lock&lt;std::mutex&gt;<sp/>lock(this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a8f6ad65d996d5b6c7c62e1990b780680" kindref="member">mutex</ref>);</highlight></codeline>
<codeline lineno="162"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a62003c15c75795b96a1144ab9542ff23" kindref="member">cv</ref>.notify_all();<sp/><sp/></highlight><highlight class="comment">//<sp/>stop<sp/>all<sp/>waiting<sp/>threads</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="163"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="164"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">for</highlight><highlight class="normal"><sp/>(</highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>i<sp/>=<sp/>0;<sp/>i<sp/>&lt;<sp/>static_cast&lt;int&gt;(this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a7f58d36428162c1e2b375113bd00151e" kindref="member">threads</ref>.size());</highlight></codeline>
<codeline lineno="165"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>++i)<sp/>{<sp/><sp/></highlight><highlight class="comment">//<sp/>wait<sp/>for<sp/>the<sp/>computing<sp/>threads<sp/>to<sp/>finish</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="166"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a7f58d36428162c1e2b375113bd00151e" kindref="member">threads</ref>[i]-&gt;joinable())<sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a7f58d36428162c1e2b375113bd00151e" kindref="member">threads</ref>[i]-&gt;join();</highlight></codeline>
<codeline lineno="167"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="168"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>if<sp/>there<sp/>were<sp/>no<sp/>threads<sp/>in<sp/>the<sp/>pool<sp/>but<sp/>some<sp/>functors<sp/>in<sp/>the<sp/>queue,<sp/>the</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="169"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>functors<sp/>are<sp/>not<sp/>deleted<sp/>by<sp/>the<sp/>threads</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="170"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>therefore<sp/>delete<sp/>them<sp/>here</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="171"><highlight class="normal"><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1aa0c16c2b18e42bfdd7ae9591b8e14ecd" kindref="member">clear_queue</ref>();</highlight></codeline>
<codeline lineno="172"><highlight class="normal"><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a7f58d36428162c1e2b375113bd00151e" kindref="member">threads</ref>.clear();</highlight></codeline>
<codeline lineno="173"><highlight class="normal"><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a9307094feb4d1f01ff0a651448f81a80" kindref="member">flags</ref>.clear();</highlight></codeline>
<codeline lineno="174"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="175"><highlight class="normal"></highlight></codeline>
<codeline lineno="177"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">template</highlight><highlight class="normal"><sp/>&lt;</highlight><highlight class="keyword">typename</highlight><highlight class="normal"><sp/>C,<sp/></highlight><highlight class="keyword">typename</highlight><highlight class="normal"><sp/>F,<sp/></highlight><highlight class="keyword">typename</highlight><highlight class="normal"><sp/>M,<sp/></highlight><highlight class="keyword">typename</highlight><highlight class="normal">...<sp/>Rest&gt;</highlight></codeline>
<codeline lineno="178" refid="classforpy_1_1threading_1_1thread__pool_1a3411c75d9e8adbc3ba7456d85db4cdc8" refkind="member"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">auto</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1threading_1_1thread__pool_1a3411c75d9e8adbc3ba7456d85db4cdc8" kindref="member">push_move</ref>(F<sp/>&amp;&amp;f,<sp/>C<sp/>*c,<sp/>M<sp/>&amp;&amp;movable,<sp/>Rest<sp/>&amp;&amp;...<sp/>rest)</highlight></codeline>
<codeline lineno="179"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>-&gt;<sp/>std::future&lt;decltype((c-&gt;*f)(</highlight><highlight class="keyword">new</highlight><highlight class="normal"><sp/><ref refid="structforpy_1_1_desk" kindref="compound">forpy::Desk</ref>(0),<sp/>movable,<sp/>rest...))&gt;<sp/>{</highlight></codeline>
<codeline lineno="180"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keyword">auto</highlight><highlight class="normal"><sp/>pck<sp/>=<sp/>std::make_shared&lt;std::packaged_task&lt;decltype(</highlight></codeline>
<codeline lineno="181"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>(c-&gt;*f)(</highlight><highlight class="keyword">new</highlight><highlight class="normal"><sp/><ref refid="structforpy_1_1_desk" kindref="compound">forpy::Desk</ref>(0),<sp/>movable,<sp/>rest...))(<ref refid="namespaceforpy_1_1threading_1a0454f9ca919afa1f786f40abecbc0ffc" kindref="member">INFOT</ref>)&gt;&gt;(</highlight></codeline>
<codeline lineno="182"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>std::bind(std::forward&lt;F&gt;(f),<sp/>std::forward&lt;C<sp/>*&gt;(c),</highlight></codeline>
<codeline lineno="183"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>std::placeholders::_1,<sp/>std::move(movable),</highlight></codeline>
<codeline lineno="184"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>std::forward&lt;Rest&gt;(rest)...));</highlight></codeline>
<codeline lineno="185"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keyword">auto</highlight><highlight class="normal"><sp/>_f<sp/>=<sp/></highlight><highlight class="keyword">new</highlight><highlight class="normal"><sp/>std::function&lt;void(INFOT)&gt;([pck](<ref refid="structforpy_1_1_desk" kindref="compound">INFOT</ref><sp/>s)<sp/>{<sp/>(*pck)(s);<sp/>});</highlight></codeline>
<codeline lineno="186"><highlight class="normal"><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a82bf22c7fe0eab4da78ea3b4eb1dd6b1" kindref="member">q</ref>.push(_f);</highlight></codeline>
<codeline lineno="187"><highlight class="normal"><sp/><sp/><sp/><sp/>std::unique_lock&lt;std::mutex&gt;<sp/>lock(this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a8f6ad65d996d5b6c7c62e1990b780680" kindref="member">mutex</ref>);</highlight></codeline>
<codeline lineno="188"><highlight class="normal"><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a62003c15c75795b96a1144ab9542ff23" kindref="member">cv</ref>.notify_one();</highlight></codeline>
<codeline lineno="189"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>pck-&gt;get_future();</highlight></codeline>
<codeline lineno="190"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="191"><highlight class="normal"></highlight></codeline>
<codeline lineno="193"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">template</highlight><highlight class="normal"><sp/>&lt;</highlight><highlight class="keyword">typename</highlight><highlight class="normal"><sp/>C,<sp/></highlight><highlight class="keyword">typename</highlight><highlight class="normal"><sp/>F,<sp/></highlight><highlight class="keyword">typename</highlight><highlight class="normal">...<sp/>Rest&gt;</highlight></codeline>
<codeline lineno="194" refid="classforpy_1_1threading_1_1thread__pool_1a29e3cdb95f388b0b21cd503c7173a4d2" refkind="member"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">auto</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1threading_1_1thread__pool_1a29e3cdb95f388b0b21cd503c7173a4d2" kindref="member">push</ref>(F<sp/>&amp;&amp;f,<sp/>C<sp/>*c,<sp/>Rest<sp/>&amp;&amp;...<sp/>rest)</highlight></codeline>
<codeline lineno="195"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>-&gt;<sp/>std::future&lt;decltype((c-&gt;*f)(</highlight><highlight class="keyword">new</highlight><highlight class="normal"><sp/><ref refid="structforpy_1_1_desk" kindref="compound">forpy::Desk</ref>(0),<sp/>rest...))&gt;<sp/>{</highlight></codeline>
<codeline lineno="196"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keyword">auto</highlight><highlight class="normal"><sp/>pck<sp/>=<sp/>std::make_shared&lt;std::packaged_task&lt;decltype(</highlight></codeline>
<codeline lineno="197"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>(c-&gt;*f)(</highlight><highlight class="keyword">new</highlight><highlight class="normal"><sp/><ref refid="structforpy_1_1_desk" kindref="compound">forpy::Desk</ref>(0),<sp/>rest...))(<ref refid="namespaceforpy_1_1threading_1a0454f9ca919afa1f786f40abecbc0ffc" kindref="member">INFOT</ref>)&gt;&gt;(</highlight></codeline>
<codeline lineno="198"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>std::bind(std::forward&lt;F&gt;(f),<sp/>std::forward&lt;C<sp/>*&gt;(c),</highlight></codeline>
<codeline lineno="199"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>std::placeholders::_1,<sp/>std::forward&lt;Rest&gt;(rest)...));</highlight></codeline>
<codeline lineno="200"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keyword">auto</highlight><highlight class="normal"><sp/>_f<sp/>=<sp/></highlight><highlight class="keyword">new</highlight><highlight class="normal"><sp/>std::function&lt;void(INFOT)&gt;([pck](<ref refid="structforpy_1_1_desk" kindref="compound">INFOT</ref><sp/>s)<sp/>{<sp/>(*pck)(s);<sp/>});</highlight></codeline>
<codeline lineno="201"><highlight class="normal"><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a82bf22c7fe0eab4da78ea3b4eb1dd6b1" kindref="member">q</ref>.push(_f);</highlight></codeline>
<codeline lineno="202"><highlight class="normal"><sp/><sp/><sp/><sp/>std::unique_lock&lt;std::mutex&gt;<sp/>lock(this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a8f6ad65d996d5b6c7c62e1990b780680" kindref="member">mutex</ref>);</highlight></codeline>
<codeline lineno="203"><highlight class="normal"><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a62003c15c75795b96a1144ab9542ff23" kindref="member">cv</ref>.notify_one();</highlight></codeline>
<codeline lineno="204"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>pck-&gt;get_future();</highlight></codeline>
<codeline lineno="205"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="206"><highlight class="normal"></highlight></codeline>
<codeline lineno="208"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">template</highlight><highlight class="normal"><sp/>&lt;</highlight><highlight class="keyword">typename</highlight><highlight class="normal"><sp/>F,<sp/></highlight><highlight class="keyword">typename</highlight><highlight class="normal">...<sp/>Rest&gt;</highlight></codeline>
<codeline lineno="209" refid="classforpy_1_1threading_1_1thread__pool_1a49cea250683b9a9fc52385789b4eae1d" refkind="member"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">auto</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1threading_1_1thread__pool_1a49cea250683b9a9fc52385789b4eae1d" kindref="member">push</ref>(F<sp/>&amp;&amp;f,<sp/>Rest<sp/>&amp;&amp;...<sp/>rest)</highlight></codeline>
<codeline lineno="210"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>-&gt;<sp/>std::future&lt;decltype(f(</highlight><highlight class="keyword">new</highlight><highlight class="normal"><sp/><ref refid="structforpy_1_1_desk" kindref="compound">forpy::Desk</ref>(0),<sp/>rest...))&gt;<sp/>{</highlight></codeline>
<codeline lineno="211"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keyword">auto</highlight><highlight class="normal"><sp/>pck<sp/>=<sp/>std::make_shared&lt;</highlight></codeline>
<codeline lineno="212"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>std::packaged_task&lt;decltype(f(</highlight><highlight class="keyword">new</highlight><highlight class="normal"><sp/><ref refid="structforpy_1_1_desk" kindref="compound">forpy::Desk</ref>(0),<sp/>rest...))(<ref refid="namespaceforpy_1_1threading_1a0454f9ca919afa1f786f40abecbc0ffc" kindref="member">INFOT</ref>)&gt;&gt;(</highlight></codeline>
<codeline lineno="213"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>std::bind(std::forward&lt;F&gt;(f),<sp/>std::placeholders::_1,</highlight></codeline>
<codeline lineno="214"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>std::forward&lt;Rest&gt;(rest)...));</highlight></codeline>
<codeline lineno="215"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keyword">auto</highlight><highlight class="normal"><sp/>_f<sp/>=<sp/></highlight><highlight class="keyword">new</highlight><highlight class="normal"><sp/>std::function&lt;void(INFOT)&gt;([pck](<ref refid="structforpy_1_1_desk" kindref="compound">INFOT</ref><sp/>s)<sp/>{<sp/>(*pck)(s);<sp/>});</highlight></codeline>
<codeline lineno="216"><highlight class="normal"><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a82bf22c7fe0eab4da78ea3b4eb1dd6b1" kindref="member">q</ref>.push(_f);</highlight></codeline>
<codeline lineno="217"><highlight class="normal"><sp/><sp/><sp/><sp/>std::unique_lock&lt;std::mutex&gt;<sp/>lock(this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a8f6ad65d996d5b6c7c62e1990b780680" kindref="member">mutex</ref>);</highlight></codeline>
<codeline lineno="218"><highlight class="normal"><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a62003c15c75795b96a1144ab9542ff23" kindref="member">cv</ref>.notify_one();</highlight></codeline>
<codeline lineno="219"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>pck-&gt;get_future();</highlight></codeline>
<codeline lineno="220"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="221"><highlight class="normal"></highlight></codeline>
<codeline lineno="223"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">template</highlight><highlight class="normal"><sp/>&lt;</highlight><highlight class="keyword">typename</highlight><highlight class="normal"><sp/>F&gt;</highlight></codeline>
<codeline lineno="224" refid="classforpy_1_1threading_1_1thread__pool_1a976e6d963880379f7f9b43ba6f533f98" refkind="member"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">auto</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1threading_1_1thread__pool_1a976e6d963880379f7f9b43ba6f533f98" kindref="member">push</ref>(F<sp/>&amp;&amp;f)<sp/>-&gt;<sp/>std::future&lt;decltype(f(new<sp/>forpy::Desk(0)))&gt;<sp/>{</highlight></codeline>
<codeline lineno="225"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keyword">auto</highlight><highlight class="normal"><sp/>pck<sp/>=<sp/>std::make_shared&lt;</highlight></codeline>
<codeline lineno="226"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>std::packaged_task&lt;decltype(f(new<sp/>forpy::Desk(0)))(INFOT)&gt;&gt;(</highlight></codeline>
<codeline lineno="227"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>std::forward&lt;F&gt;(f));</highlight></codeline>
<codeline lineno="228"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keyword">auto</highlight><highlight class="normal"><sp/>_f<sp/>=<sp/></highlight><highlight class="keyword">new</highlight><highlight class="normal"><sp/>std::function&lt;void(INFOT)&gt;([pck](<ref refid="structforpy_1_1_desk" kindref="compound">INFOT</ref><sp/>s)<sp/>{<sp/>(*pck)(s);<sp/>});</highlight></codeline>
<codeline lineno="229"><highlight class="normal"><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a82bf22c7fe0eab4da78ea3b4eb1dd6b1" kindref="member">q</ref>.push(_f);</highlight></codeline>
<codeline lineno="230"><highlight class="normal"><sp/><sp/><sp/><sp/>std::unique_lock&lt;std::mutex&gt;<sp/>lock(this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a8f6ad65d996d5b6c7c62e1990b780680" kindref="member">mutex</ref>);</highlight></codeline>
<codeline lineno="231"><highlight class="normal"><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a62003c15c75795b96a1144ab9542ff23" kindref="member">cv</ref>.notify_one();</highlight></codeline>
<codeline lineno="232"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>pck-&gt;get_future();</highlight></codeline>
<codeline lineno="233"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="234"><highlight class="normal"></highlight></codeline>
<codeline lineno="235" refid="classforpy_1_1threading_1_1thread__pool_1a28759c9a177e27fa6488457e36edf971" refkind="member"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1threading_1_1thread__pool_1a28759c9a177e27fa6488457e36edf971" kindref="member">init</ref>()<sp/>{</highlight></codeline>
<codeline lineno="236"><highlight class="normal"><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a2441eb7bc713bc66c89532a721f6cb19" kindref="member">nWaiting</ref><sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="237"><highlight class="normal"><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1ad54e73503f80bb369ef816c979d5263e" kindref="member">isStop</ref><sp/>=<sp/></highlight><highlight class="keyword">false</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="238"><highlight class="normal"><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1ab875f9f5d7cf0f773d8682bec5986a78" kindref="member">isDone</ref><sp/>=<sp/></highlight><highlight class="keyword">false</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="239"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="240"><highlight class="normal"></highlight></codeline>
<codeline lineno="241"><highlight class="normal"><sp/></highlight><highlight class="keyword">private</highlight><highlight class="normal">:</highlight></codeline>
<codeline lineno="242"><highlight class="normal"><sp/><sp/></highlight><highlight class="comment">//<sp/>deleted</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="243"><highlight class="normal"><sp/><sp/><ref refid="classforpy_1_1threading_1_1thread__pool_1a60bf54202abc186b165f123df1bd24cf" kindref="member">thread_pool</ref>(</highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1threading_1_1thread__pool" kindref="compound">thread_pool</ref><sp/>&amp;)<sp/>=<sp/></highlight><highlight class="keyword">delete</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="244"><highlight class="normal"><sp/><sp/><ref refid="classforpy_1_1threading_1_1thread__pool_1a60bf54202abc186b165f123df1bd24cf" kindref="member">thread_pool</ref>(<ref refid="classforpy_1_1threading_1_1thread__pool" kindref="compound">thread_pool</ref><sp/>&amp;&amp;)<sp/>=<sp/></highlight><highlight class="keyword">delete</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="245"><highlight class="normal"><sp/><sp/><ref refid="classforpy_1_1threading_1_1thread__pool" kindref="compound">thread_pool</ref><sp/>&amp;<ref refid="classforpy_1_1threading_1_1thread__pool_1a70cefd6ac406d82cc720f157c641acbe" kindref="member">operator=</ref>(</highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1threading_1_1thread__pool" kindref="compound">thread_pool</ref><sp/>&amp;)<sp/>=<sp/></highlight><highlight class="keyword">delete</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="246"><highlight class="normal"><sp/><sp/><ref refid="classforpy_1_1threading_1_1thread__pool" kindref="compound">thread_pool</ref><sp/>&amp;<ref refid="classforpy_1_1threading_1_1thread__pool_1a70cefd6ac406d82cc720f157c641acbe" kindref="member">operator=</ref>(<ref refid="classforpy_1_1threading_1_1thread__pool" kindref="compound">thread_pool</ref><sp/>&amp;&amp;)<sp/>=<sp/></highlight><highlight class="keyword">delete</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="247"><highlight class="normal"></highlight></codeline>
<codeline lineno="248" refid="classforpy_1_1threading_1_1thread__pool_1a6b4c6c47566081aedf7c6e6400aa9a87" refkind="member"><highlight class="normal"><sp/><sp/></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1threading_1_1thread__pool_1a6b4c6c47566081aedf7c6e6400aa9a87" kindref="member">set_thread</ref>(</highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>i)<sp/>{</highlight></codeline>
<codeline lineno="249"><highlight class="normal"><sp/><sp/><sp/><sp/>std::shared_ptr&lt;std::atomic&lt;bool&gt;&gt;<sp/>flag(</highlight></codeline>
<codeline lineno="250"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a9307094feb4d1f01ff0a651448f81a80" kindref="member">flags</ref>[i]);<sp/><sp/></highlight><highlight class="comment">//<sp/>a<sp/>copy<sp/>of<sp/>the<sp/>shared<sp/>ptr<sp/>to<sp/>the<sp/>flag</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="251"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keyword">auto</highlight><highlight class="normal"><sp/>f<sp/>=<sp/>[</highlight><highlight class="keyword">this</highlight><highlight class="normal">,<sp/>i,<sp/>flag<sp/></highlight><highlight class="comment">/*<sp/>a<sp/>copy<sp/>of<sp/>the<sp/>shared<sp/>ptr<sp/>to<sp/>the<sp/>flag<sp/>*/</highlight><highlight class="normal">]()<sp/>{</highlight></codeline>
<codeline lineno="252"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>VLOG(3)<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;Starting<sp/>up<sp/>thread<sp/>&quot;</highlight><highlight class="normal"><sp/>&lt;&lt;<sp/>i<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;<sp/>(id<sp/>&quot;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="253"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>&lt;&lt;<sp/>std::this_thread::get_id()<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;).&quot;</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="254"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="structforpy_1_1_desk" kindref="compound">forpy::Desk</ref><sp/>d(i);</highlight></codeline>
<codeline lineno="255"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>std::atomic&lt;bool&gt;<sp/>&amp;_flag<sp/>=<sp/>*flag;</highlight></codeline>
<codeline lineno="256"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>std::function&lt;void(INFOT)&gt;<sp/>*_f;</highlight></codeline>
<codeline lineno="257"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordtype">bool</highlight><highlight class="normal"><sp/>isPop<sp/>=<sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a82bf22c7fe0eab4da78ea3b4eb1dd6b1" kindref="member">q</ref>.pop(_f);</highlight></codeline>
<codeline lineno="258"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">while</highlight><highlight class="normal"><sp/>(</highlight><highlight class="keyword">true</highlight><highlight class="normal">)<sp/>{</highlight></codeline>
<codeline lineno="259"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">while</highlight><highlight class="normal"><sp/>(isPop)<sp/>{<sp/><sp/></highlight><highlight class="comment">//<sp/>if<sp/>there<sp/>is<sp/>anything<sp/>in<sp/>the<sp/>queue</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="260"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>std::unique_ptr&lt;std::function&lt;void(INFOT)&gt;&gt;<sp/>func(</highlight></codeline>
<codeline lineno="261"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>_f);<sp/><sp/></highlight><highlight class="comment">//<sp/>at<sp/>return,<sp/>delete<sp/>the<sp/>function<sp/>even<sp/>if<sp/>an<sp/>exception</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="262"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>occurred</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="263"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>(*_f)(&amp;d);</highlight></codeline>
<codeline lineno="264"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>d.<ref refid="structforpy_1_1_desk_1a2fbf32e58f1d4b04d567962a4f62612e" kindref="member">reset</ref>();</highlight></codeline>
<codeline lineno="265"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(_flag)</highlight></codeline>
<codeline lineno="266"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal">;<sp/><sp/></highlight><highlight class="comment">//<sp/>the<sp/>thread<sp/>is<sp/>wanted<sp/>to<sp/>stop,<sp/>return<sp/>even<sp/>if<sp/>the<sp/>queue</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="267"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>is<sp/>not<sp/>empty<sp/>yet</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="268"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="269"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>isPop<sp/>=<sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a82bf22c7fe0eab4da78ea3b4eb1dd6b1" kindref="member">q</ref>.pop(_f);</highlight></codeline>
<codeline lineno="270"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="271"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>the<sp/>queue<sp/>is<sp/>empty<sp/>here,<sp/>wait<sp/>for<sp/>the<sp/>next<sp/>command</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="272"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>std::unique_lock&lt;std::mutex&gt;<sp/>lock(this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a8f6ad65d996d5b6c7c62e1990b780680" kindref="member">mutex</ref>);</highlight></codeline>
<codeline lineno="273"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>++this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a2441eb7bc713bc66c89532a721f6cb19" kindref="member">nWaiting</ref>;</highlight></codeline>
<codeline lineno="274"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a62003c15c75795b96a1144ab9542ff23" kindref="member">cv</ref>.wait(lock,<sp/>[</highlight><highlight class="keyword">this</highlight><highlight class="normal">,<sp/>&amp;_f,<sp/>&amp;isPop,<sp/>&amp;_flag]()<sp/>{</highlight></codeline>
<codeline lineno="275"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>isPop<sp/>=<sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a82bf22c7fe0eab4da78ea3b4eb1dd6b1" kindref="member">q</ref>.pop(_f);</highlight></codeline>
<codeline lineno="276"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>isPop<sp/>||<sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1ab875f9f5d7cf0f773d8682bec5986a78" kindref="member">isDone</ref><sp/>||<sp/>_flag;</highlight></codeline>
<codeline lineno="277"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>});</highlight></codeline>
<codeline lineno="278"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>--this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a2441eb7bc713bc66c89532a721f6cb19" kindref="member">nWaiting</ref>;</highlight></codeline>
<codeline lineno="279"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(!isPop)</highlight></codeline>
<codeline lineno="280"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal">;<sp/><sp/></highlight><highlight class="comment">//<sp/>if<sp/>the<sp/>queue<sp/>is<sp/>empty<sp/>and<sp/>this-&gt;isDone<sp/>==<sp/>true<sp/>or<sp/>*flag</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="281"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>then<sp/>return</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="282"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="283"><highlight class="normal"><sp/><sp/><sp/><sp/>};</highlight></codeline>
<codeline lineno="284"><highlight class="normal"><sp/><sp/><sp/><sp/>this-&gt;<ref refid="classforpy_1_1threading_1_1thread__pool_1a7f58d36428162c1e2b375113bd00151e" kindref="member">threads</ref>[i].reset(</highlight></codeline>
<codeline lineno="285"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keyword">new</highlight><highlight class="normal"><sp/>std::thread(f));<sp/><sp/></highlight><highlight class="comment">//<sp/>compiler<sp/>may<sp/>not<sp/>support<sp/>std::make_unique()</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="286"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="287"><highlight class="normal"></highlight></codeline>
<codeline lineno="288" refid="classforpy_1_1threading_1_1thread__pool_1a7f58d36428162c1e2b375113bd00151e" refkind="member"><highlight class="normal"><sp/><sp/>std::vector&lt;std::unique_ptr&lt;std::thread&gt;&gt;<sp/><ref refid="classforpy_1_1threading_1_1thread__pool_1a7f58d36428162c1e2b375113bd00151e" kindref="member">threads</ref>;</highlight></codeline>
<codeline lineno="289" refid="classforpy_1_1threading_1_1thread__pool_1a9307094feb4d1f01ff0a651448f81a80" refkind="member"><highlight class="normal"><sp/><sp/>std::vector&lt;std::shared_ptr&lt;std::atomic&lt;bool&gt;&gt;&gt;<sp/><ref refid="classforpy_1_1threading_1_1thread__pool_1a9307094feb4d1f01ff0a651448f81a80" kindref="member">flags</ref>;</highlight></codeline>
<codeline lineno="290" refid="classforpy_1_1threading_1_1thread__pool_1a82bf22c7fe0eab4da78ea3b4eb1dd6b1" refkind="member"><highlight class="normal"><sp/><sp/><ref refid="classforpy_1_1threading_1_1detail_1_1_queue" kindref="compound">detail::Queue&lt;std::function&lt;void(INFOT)&gt;</ref><sp/>*&gt;<sp/><ref refid="classforpy_1_1threading_1_1thread__pool_1a82bf22c7fe0eab4da78ea3b4eb1dd6b1" kindref="member">q</ref>;</highlight></codeline>
<codeline lineno="291" refid="classforpy_1_1threading_1_1thread__pool_1ab875f9f5d7cf0f773d8682bec5986a78" refkind="member"><highlight class="normal"><sp/><sp/>std::atomic&lt;bool&gt;<sp/><ref refid="classforpy_1_1threading_1_1thread__pool_1ab875f9f5d7cf0f773d8682bec5986a78" kindref="member">isDone</ref>;</highlight></codeline>
<codeline lineno="292" refid="classforpy_1_1threading_1_1thread__pool_1ad54e73503f80bb369ef816c979d5263e" refkind="member"><highlight class="normal"><sp/><sp/>std::atomic&lt;bool&gt;<sp/><ref refid="classforpy_1_1threading_1_1thread__pool_1ad54e73503f80bb369ef816c979d5263e" kindref="member">isStop</ref>;</highlight></codeline>
<codeline lineno="293" refid="classforpy_1_1threading_1_1thread__pool_1a2441eb7bc713bc66c89532a721f6cb19" refkind="member"><highlight class="normal"><sp/><sp/>std::atomic&lt;int&gt;<sp/><ref refid="classforpy_1_1threading_1_1thread__pool_1a2441eb7bc713bc66c89532a721f6cb19" kindref="member">nWaiting</ref>;<sp/><sp/></highlight><highlight class="comment">//<sp/>how<sp/>many<sp/>threads<sp/>are<sp/>waiting</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="294"><highlight class="normal"></highlight></codeline>
<codeline lineno="295" refid="classforpy_1_1threading_1_1thread__pool_1a8f6ad65d996d5b6c7c62e1990b780680" refkind="member"><highlight class="normal"><sp/><sp/>std::mutex<sp/><ref refid="classforpy_1_1threading_1_1thread__pool_1a8f6ad65d996d5b6c7c62e1990b780680" kindref="member">mutex</ref>;</highlight></codeline>
<codeline lineno="296" refid="classforpy_1_1threading_1_1thread__pool_1a62003c15c75795b96a1144ab9542ff23" refkind="member"><highlight class="normal"><sp/><sp/>std::condition_variable<sp/><ref refid="classforpy_1_1threading_1_1thread__pool_1a62003c15c75795b96a1144ab9542ff23" kindref="member">cv</ref>;</highlight></codeline>
<codeline lineno="297"><highlight class="normal">};</highlight></codeline>
<codeline lineno="298"><highlight class="normal">}<sp/><sp/></highlight><highlight class="comment">//<sp/>namespace<sp/>threading</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="299"><highlight class="normal"></highlight></codeline>
<codeline lineno="300" refid="classforpy_1_1_thread_control" refkind="compound"><highlight class="normal"></highlight><highlight class="keyword">class<sp/></highlight><highlight class="normal"><ref refid="classforpy_1_1_thread_control" kindref="compound">ThreadControl</ref><sp/>{</highlight></codeline>
<codeline lineno="301"><highlight class="normal"><sp/></highlight><highlight class="keyword">private</highlight><highlight class="normal">:</highlight></codeline>
<codeline lineno="302" refid="classforpy_1_1_thread_control_1ae6bc7e2ee638612891f8642d24aa4ed5" refkind="member"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">inline</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1_thread_control_1ae6bc7e2ee638612891f8642d24aa4ed5" kindref="member">ThreadControl</ref>()<sp/>:<sp/><ref refid="classforpy_1_1_thread_control_1abf7578c3912777861f07cfef925b49b3" kindref="member">ttp</ref>()<sp/>{</highlight></codeline>
<codeline lineno="303"><highlight class="normal"><sp/><sp/><sp/><sp/>VLOG(1)<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;Creating<sp/>thread<sp/>control<sp/>(main<sp/>thread<sp/>id:<sp/>&quot;</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="304"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>&lt;&lt;<sp/>std::this_thread::get_id()<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;).&quot;</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="305"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="306"><highlight class="normal"><sp/><sp/><ref refid="classforpy_1_1_thread_control_1a426a23de1f70a330c883aaebfa60d4cb" kindref="member">DISALLOW_COPY_AND_ASSIGN</ref>(<ref refid="classforpy_1_1_thread_control" kindref="compound">ThreadControl</ref>);</highlight></codeline>
<codeline lineno="307" refid="classforpy_1_1_thread_control_1abf7578c3912777861f07cfef925b49b3" refkind="member"><highlight class="normal"><sp/><sp/>std::unique_ptr&lt;threading::thread_pool&gt;<sp/><ref refid="classforpy_1_1_thread_control_1abf7578c3912777861f07cfef925b49b3" kindref="member">ttp</ref>;</highlight></codeline>
<codeline lineno="308"><highlight class="normal"></highlight></codeline>
<codeline lineno="309"><highlight class="normal"><sp/></highlight><highlight class="keyword">public</highlight><highlight class="normal">:</highlight></codeline>
<codeline lineno="310" refid="classforpy_1_1_thread_control_1aa1c69ee104ac7ee426894340bf8c6528" refkind="member"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">inline</highlight><highlight class="normal"><sp/></highlight><highlight class="keyword">static</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1_thread_control" kindref="compound">ThreadControl</ref><sp/>&amp;<ref refid="classforpy_1_1_thread_control_1aa1c69ee104ac7ee426894340bf8c6528" kindref="member">getInstance</ref>()<sp/>{</highlight></codeline>
<codeline lineno="311"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keyword">static</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1_thread_control" kindref="compound">ThreadControl</ref><sp/>instance;</highlight></codeline>
<codeline lineno="312"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>instance;</highlight></codeline>
<codeline lineno="313"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="314"><highlight class="normal"></highlight></codeline>
<codeline lineno="315" refid="classforpy_1_1_thread_control_1aedabd435b20bc64d146d44e6904b3fa8" refkind="member"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">inline</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1_thread_control_1aedabd435b20bc64d146d44e6904b3fa8" kindref="member">set_num</ref>(</highlight><highlight class="keywordtype">size_t</highlight><highlight class="normal"><sp/>n)<sp/>{</highlight></codeline>
<codeline lineno="316"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(n<sp/>==<sp/>0)<sp/>n<sp/>=<sp/>std::thread::hardware_concurrency();</highlight></codeline>
<codeline lineno="317"><highlight class="normal"><sp/><sp/><sp/><sp/>VLOG(1)<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;Setting<sp/>thread<sp/>pool<sp/>size<sp/>to<sp/>&quot;</highlight><highlight class="normal"><sp/>&lt;&lt;<sp/>n<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;.&quot;</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="318"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="classforpy_1_1_thread_control_1abf7578c3912777861f07cfef925b49b3" kindref="member">ttp</ref><sp/>==<sp/></highlight><highlight class="keyword">nullptr</highlight><highlight class="normal">)<sp/>{</highlight></codeline>
<codeline lineno="319"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>VLOG(1)<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;Initializing<sp/>thread<sp/>pool<sp/>from<sp/>scratch.&quot;</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="320"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="classforpy_1_1_thread_control_1abf7578c3912777861f07cfef925b49b3" kindref="member">ttp</ref><sp/>=<sp/>std::make_unique&lt;threading::thread_pool&gt;(n);</highlight></codeline>
<codeline lineno="321"><highlight class="normal"><sp/><sp/><sp/><sp/>}<sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"><sp/>{</highlight></codeline>
<codeline lineno="322"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="classforpy_1_1_thread_control_1a51f18400b5ef897f11df5077d92bad58" kindref="member">get_num</ref>()<sp/>!=<sp/>n)<sp/>{</highlight></codeline>
<codeline lineno="323"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>VLOG(1)<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;Resizing<sp/>thread<sp/>pool.&quot;</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="324"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="classforpy_1_1_thread_control_1abf7578c3912777861f07cfef925b49b3" kindref="member">ttp</ref>-&gt;resize(n);</highlight></codeline>
<codeline lineno="325"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="326"><highlight class="normal"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="327"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="328"><highlight class="normal"></highlight></codeline>
<codeline lineno="329" refid="classforpy_1_1_thread_control_1a51f18400b5ef897f11df5077d92bad58" refkind="member"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">inline</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">size_t</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1_thread_control_1a51f18400b5ef897f11df5077d92bad58" kindref="member">get_num</ref>()<sp/>{</highlight></codeline>
<codeline lineno="330"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="classforpy_1_1_thread_control_1abf7578c3912777861f07cfef925b49b3" kindref="member">ttp</ref><sp/>==<sp/></highlight><highlight class="keyword">nullptr</highlight><highlight class="normal">)</highlight></codeline>
<codeline lineno="331"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="332"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="333"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1_thread_control_1abf7578c3912777861f07cfef925b49b3" kindref="member">ttp</ref>-&gt;size();</highlight></codeline>
<codeline lineno="334"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="335"><highlight class="normal"></highlight></codeline>
<codeline lineno="336" refid="classforpy_1_1_thread_control_1a2dd1bd07f64bccf6cb853760b22a1fc6" refkind="member"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">inline</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">size_t</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1_thread_control_1a2dd1bd07f64bccf6cb853760b22a1fc6" kindref="member">get_idle</ref>()<sp/>{</highlight></codeline>
<codeline lineno="337"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">if</highlight><highlight class="normal"><sp/>(<ref refid="classforpy_1_1_thread_control_1abf7578c3912777861f07cfef925b49b3" kindref="member">ttp</ref><sp/>==<sp/></highlight><highlight class="keyword">nullptr</highlight><highlight class="normal">)</highlight></codeline>
<codeline lineno="338"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline lineno="339"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">else</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="340"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1_thread_control_1abf7578c3912777861f07cfef925b49b3" kindref="member">ttp</ref>-&gt;n_idle();</highlight></codeline>
<codeline lineno="341"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="342"><highlight class="normal"></highlight></codeline>
<codeline lineno="344"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">template</highlight><highlight class="normal"><sp/>&lt;</highlight><highlight class="keyword">typename</highlight><highlight class="normal"><sp/>C,<sp/></highlight><highlight class="keyword">typename</highlight><highlight class="normal"><sp/>F,<sp/></highlight><highlight class="keyword">typename</highlight><highlight class="normal"><sp/>M,<sp/></highlight><highlight class="keyword">typename</highlight><highlight class="normal">...<sp/>Rest&gt;</highlight></codeline>
<codeline lineno="345" refid="classforpy_1_1_thread_control_1a57bb4d6430a10c5dd955d2de1abdf023" refkind="member"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">auto</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1_thread_control_1a57bb4d6430a10c5dd955d2de1abdf023" kindref="member">push_move</ref>(F<sp/>&amp;&amp;f,<sp/>C<sp/>*c,<sp/>M<sp/>&amp;&amp;movable,<sp/>Rest<sp/>&amp;&amp;...<sp/>rest)</highlight></codeline>
<codeline lineno="346"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>-&gt;<sp/>std::future&lt;decltype((c-&gt;*f)(</highlight><highlight class="keyword">new</highlight><highlight class="normal"><sp/><ref refid="structforpy_1_1_desk" kindref="compound">forpy::Desk</ref>(0),<sp/>movable,<sp/>rest...))&gt;<sp/>{</highlight></codeline>
<codeline lineno="347"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1_thread_control_1abf7578c3912777861f07cfef925b49b3" kindref="member">ttp</ref>-&gt;push_move(f,<sp/>c,<sp/>movable,<sp/>rest...);</highlight></codeline>
<codeline lineno="348"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="349"><highlight class="normal"></highlight></codeline>
<codeline lineno="350"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">template</highlight><highlight class="normal"><sp/>&lt;</highlight><highlight class="keyword">typename</highlight><highlight class="normal"><sp/>C,<sp/></highlight><highlight class="keyword">typename</highlight><highlight class="normal"><sp/>F,<sp/></highlight><highlight class="keyword">typename</highlight><highlight class="normal">...<sp/>Rest&gt;</highlight></codeline>
<codeline lineno="351" refid="classforpy_1_1_thread_control_1a9a571c8aff74a8b5a8d1f35e2f78c5bf" refkind="member"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">auto</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1_thread_control_1a9a571c8aff74a8b5a8d1f35e2f78c5bf" kindref="member">push</ref>(F<sp/>&amp;&amp;f,<sp/>C<sp/>*c,<sp/>Rest<sp/>&amp;&amp;...<sp/>rest)</highlight></codeline>
<codeline lineno="352"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>-&gt;<sp/>std::future&lt;decltype((c-&gt;*f)(</highlight><highlight class="keyword">new</highlight><highlight class="normal"><sp/><ref refid="structforpy_1_1_desk" kindref="compound">forpy::Desk</ref>(0),<sp/>rest...))&gt;<sp/>{</highlight></codeline>
<codeline lineno="353"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1_thread_control_1abf7578c3912777861f07cfef925b49b3" kindref="member">ttp</ref>-&gt;push(f,<sp/>c,<sp/>rest...);</highlight></codeline>
<codeline lineno="354"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="355"><highlight class="normal"></highlight></codeline>
<codeline lineno="356"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">template</highlight><highlight class="normal"><sp/>&lt;</highlight><highlight class="keyword">typename</highlight><highlight class="normal"><sp/>F,<sp/></highlight><highlight class="keyword">typename</highlight><highlight class="normal">...<sp/>Rest&gt;</highlight></codeline>
<codeline lineno="357" refid="classforpy_1_1_thread_control_1a780dfd52ce073ba59f5dcc0471aa87bc" refkind="member"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">auto</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1_thread_control_1a780dfd52ce073ba59f5dcc0471aa87bc" kindref="member">push</ref>(F<sp/>&amp;&amp;f,<sp/>Rest<sp/>&amp;&amp;...<sp/>rest)</highlight></codeline>
<codeline lineno="358"><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/>-&gt;<sp/>std::future&lt;decltype(f(</highlight><highlight class="keyword">new</highlight><highlight class="normal"><sp/><ref refid="structforpy_1_1_desk" kindref="compound">Desk</ref>(0),<sp/>rest...))&gt;<sp/>{</highlight></codeline>
<codeline lineno="359"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1_thread_control_1abf7578c3912777861f07cfef925b49b3" kindref="member">ttp</ref>-&gt;push(f,<sp/>rest...);</highlight></codeline>
<codeline lineno="360"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="361"><highlight class="normal"></highlight></codeline>
<codeline lineno="362"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">template</highlight><highlight class="normal"><sp/>&lt;</highlight><highlight class="keyword">typename</highlight><highlight class="normal"><sp/>F&gt;</highlight></codeline>
<codeline lineno="363" refid="classforpy_1_1_thread_control_1ad029013c63ffe66d16e061e7fe93aecc" refkind="member"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">auto</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1_thread_control_1ad029013c63ffe66d16e061e7fe93aecc" kindref="member">push</ref>(F<sp/>&amp;&amp;f)<sp/>-&gt;<sp/>std::future&lt;decltype(f(new<sp/>Desk(0)))&gt;<sp/>{</highlight></codeline>
<codeline lineno="364"><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1_thread_control_1abf7578c3912777861f07cfef925b49b3" kindref="member">ttp</ref>-&gt;push(f);</highlight></codeline>
<codeline lineno="365"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="366"><highlight class="normal"></highlight></codeline>
<codeline lineno="367" refid="classforpy_1_1_thread_control_1ac926db74a6c0bd18a118398a0763d43d" refkind="member"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">inline</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">void</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1_thread_control_1ac926db74a6c0bd18a118398a0763d43d" kindref="member">stop</ref>(</highlight><highlight class="keyword">const</highlight><highlight class="normal"><sp/></highlight><highlight class="keywordtype">bool</highlight><highlight class="normal"><sp/>&amp;wait<sp/>=<sp/></highlight><highlight class="keyword">false</highlight><highlight class="normal">)<sp/>{</highlight></codeline>
<codeline lineno="368"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="classforpy_1_1_thread_control_1abf7578c3912777861f07cfef925b49b3" kindref="member">ttp</ref>-&gt;stop(wait);</highlight></codeline>
<codeline lineno="369"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="classforpy_1_1_thread_control_1abf7578c3912777861f07cfef925b49b3" kindref="member">ttp</ref>-&gt;init();</highlight></codeline>
<codeline lineno="370"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="371"><highlight class="normal"></highlight></codeline>
<codeline lineno="372" refid="classforpy_1_1_thread_control_1a47aed3131614927ccbd654c08d1f1e35" refkind="member"><highlight class="normal"><sp/><sp/></highlight><highlight class="keyword">inline</highlight><highlight class="normal"><sp/><ref refid="classforpy_1_1_thread_control_1a47aed3131614927ccbd654c08d1f1e35" kindref="member">~ThreadControl</ref>()<sp/>{</highlight></codeline>
<codeline lineno="373"><highlight class="normal"><sp/><sp/><sp/><sp/>VLOG(1)<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;Destroying<sp/>thread<sp/>control...&quot;</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="374"><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="classforpy_1_1_thread_control_1abf7578c3912777861f07cfef925b49b3" kindref="member">ttp</ref>.reset();</highlight></codeline>
<codeline lineno="375"><highlight class="normal"><sp/><sp/><sp/><sp/>VLOG(1)<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;Done.&quot;</highlight><highlight class="normal">;</highlight></codeline>
<codeline lineno="376"><highlight class="normal"><sp/><sp/>}</highlight></codeline>
<codeline lineno="377"><highlight class="normal">};</highlight></codeline>
<codeline lineno="378"><highlight class="normal"></highlight></codeline>
<codeline lineno="379"><highlight class="normal">}<sp/><sp/></highlight><highlight class="comment">//<sp/>namespace<sp/>forpy</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="380"><highlight class="normal"></highlight></codeline>
<codeline lineno="381"><highlight class="normal"></highlight><highlight class="preprocessor">#endif<sp/><sp/>//<sp/>FORPY_UTIL_THREADING_CTPL_H_</highlight></codeline>
    </programlisting>
    <location file="/Users/classner/git/forpy/include/forpy/util/threading/ctpl.h"/>
  </compounddef>
</doxygen>
