<?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.9.6" xml:lang="en-US">
  <compounddef id="classtf_1_1Semaphore" kind="class" language="C++" prot="public">
    <compoundname>tf::Semaphore</compoundname>
    <derivedcompoundref refid="classtf_1_1CriticalSection" prot="public" virt="non-virtual">tf::CriticalSection</derivedcompoundref>
    <includes refid="semaphore_8hpp" local="no">semaphore.hpp</includes>
      <sectiondef kind="friend">
      <memberdef kind="friend" id="classtf_1_1Semaphore_1a6db9d28bd448a131448276ee03de1e6d" prot="private" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
        <type>class</type>
        <definition>friend class Node</definition>
        <argsstring></argsstring>
        <name>Node</name>
        <qualifiedname>tf::Semaphore::Node</qualifiedname>
        <param>
          <type>Node</type>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="/Users/twhuang/Code/taskflow/taskflow/core/semaphore.hpp" line="70" column="16" bodyfile="/Users/twhuang/Code/taskflow/taskflow/core/semaphore.hpp" bodystart="70" bodyend="-1"/>
      </memberdef>
      </sectiondef>
      <sectiondef kind="private-attrib">
      <memberdef kind="variable" id="classtf_1_1Semaphore_1a329424188b5287ca596f1af3f6db58f1" prot="private" static="no" mutable="no">
        <type><ref refid="cpp/thread/mutex" kindref="compound" external="/Users/twhuang/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml">std::mutex</ref></type>
        <definition>std::mutex tf::Semaphore::_mtx</definition>
        <argsstring></argsstring>
        <name>_mtx</name>
        <qualifiedname>tf::Semaphore::_mtx</qualifiedname>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="/Users/twhuang/Code/taskflow/taskflow/core/semaphore.hpp" line="93" column="16" bodyfile="/Users/twhuang/Code/taskflow/taskflow/core/semaphore.hpp" bodystart="93" bodyend="-1"/>
      </memberdef>
      <memberdef kind="variable" id="classtf_1_1Semaphore_1a385c4e1622677e20bb53b01c8eb85e9b" prot="private" static="no" mutable="no">
        <type>size_t</type>
        <definition>size_t tf::Semaphore::_counter</definition>
        <argsstring></argsstring>
        <name>_counter</name>
        <qualifiedname>tf::Semaphore::_counter</qualifiedname>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="/Users/twhuang/Code/taskflow/taskflow/core/semaphore.hpp" line="95" column="12" bodyfile="/Users/twhuang/Code/taskflow/taskflow/core/semaphore.hpp" bodystart="95" bodyend="-1"/>
      </memberdef>
      <memberdef kind="variable" id="classtf_1_1Semaphore_1ab05d171c0852d2c6584d62de004f52fb" prot="private" static="no" mutable="no">
        <type><ref refid="cpp/container/vector" kindref="compound" external="/Users/twhuang/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml">std::vector</ref>&lt; Node * &gt;</type>
        <definition>std::vector&lt;Node*&gt; tf::Semaphore::_waiters</definition>
        <argsstring></argsstring>
        <name>_waiters</name>
        <qualifiedname>tf::Semaphore::_waiters</qualifiedname>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="/Users/twhuang/Code/taskflow/taskflow/core/semaphore.hpp" line="97" column="17" bodyfile="/Users/twhuang/Code/taskflow/taskflow/core/semaphore.hpp" bodystart="97" bodyend="-1"/>
      </memberdef>
      </sectiondef>
      <sectiondef kind="public-func">
      <memberdef kind="function" id="classtf_1_1Semaphore_1a70ffe5c1611dba350d105b70377f8cd2" prot="public" static="no" const="no" explicit="yes" inline="yes" virt="non-virtual">
        <type></type>
        <definition>tf::Semaphore::Semaphore</definition>
        <argsstring>(size_t max_workers)</argsstring>
        <name>Semaphore</name>
        <qualifiedname>tf::Semaphore::Semaphore</qualifiedname>
        <param>
          <type>size_t</type>
          <declname>max_workers</declname>
        </param>
        <briefdescription>
<para>constructs a semaphore with the given counter </para>
        </briefdescription>
        <detaileddescription>
<para>A semaphore creates a constraint that limits the maximum concurrency, i.e., the number of workers, in a set of tasks.</para>
<para><programlisting filename=".cpp"><codeline><highlight class="normal"><ref refid="classtf_1_1Semaphore" kindref="compound">tf::Semaphore</ref><sp/>semaphore(4);<sp/><sp/></highlight><highlight class="comment">//<sp/>concurrency<sp/>constraint<sp/>of<sp/>4<sp/>workers</highlight></codeline>
</programlisting> </para>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="/Users/twhuang/Code/taskflow/taskflow/core/semaphore.hpp" line="84" column="14" bodyfile="/Users/twhuang/Code/taskflow/taskflow/core/semaphore.hpp" bodystart="104" bodyend="106"/>
      </memberdef>
      <memberdef kind="function" id="classtf_1_1Semaphore_1a8e4236750edd903ec0492231076ba2ba" prot="public" static="no" const="yes" explicit="no" inline="yes" virt="non-virtual">
        <type>size_t</type>
        <definition>size_t tf::Semaphore::count</definition>
        <argsstring>() const</argsstring>
        <name>count</name>
        <qualifiedname>tf::Semaphore::count</qualifiedname>
        <briefdescription>
<para>queries the counter value (not thread-safe during the run) </para>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="/Users/twhuang/Code/taskflow/taskflow/core/semaphore.hpp" line="89" column="12" bodyfile="/Users/twhuang/Code/taskflow/taskflow/core/semaphore.hpp" bodystart="127" bodyend="129"/>
      </memberdef>
      </sectiondef>
      <sectiondef kind="private-func">
      <memberdef kind="function" id="classtf_1_1Semaphore_1aeb12ad1db7794e13829a0a62549d157b" prot="private" static="no" const="no" explicit="no" inline="yes" virt="non-virtual">
        <type>bool</type>
        <definition>bool tf::Semaphore::_try_acquire_or_wait</definition>
        <argsstring>(Node *)</argsstring>
        <name>_try_acquire_or_wait</name>
        <qualifiedname>tf::Semaphore::_try_acquire_or_wait</qualifiedname>
        <param>
          <type>Node *</type>
          <defname>me</defname>
        </param>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="/Users/twhuang/Code/taskflow/taskflow/core/semaphore.hpp" line="99" column="10" bodyfile="/Users/twhuang/Code/taskflow/taskflow/core/semaphore.hpp" bodystart="108" bodyend="118"/>
      </memberdef>
      <memberdef kind="function" id="classtf_1_1Semaphore_1a47b8ed63d5deecb0878a0b9cc99da20e" prot="private" static="no" const="no" explicit="no" inline="yes" virt="non-virtual">
        <type><ref refid="cpp/container/vector" kindref="compound" external="/Users/twhuang/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml">std::vector</ref>&lt; Node * &gt;</type>
        <definition>std::vector&lt; Node * &gt; tf::Semaphore::_release</definition>
        <argsstring>()</argsstring>
        <name>_release</name>
        <qualifiedname>tf::Semaphore::_release</qualifiedname>
        <briefdescription>
        </briefdescription>
        <detaileddescription>
        </detaileddescription>
        <inbodydescription>
        </inbodydescription>
        <location file="/Users/twhuang/Code/taskflow/taskflow/core/semaphore.hpp" line="101" column="17" bodyfile="/Users/twhuang/Code/taskflow/taskflow/core/semaphore.hpp" bodystart="120" bodyend="125"/>
      </memberdef>
      </sectiondef>
    <briefdescription>
<para>class to create a semophore object for building a concurrency constraint </para>
    </briefdescription>
    <detaileddescription>
<para>A semaphore creates a constraint that limits the maximum concurrency, i.e., the number of workers, in a set of tasks. You can let a task acquire/release one or multiple semaphores before/after executing its work. A task can acquire and release a semaphore, or just acquire or just release it. A <ref refid="classtf_1_1Semaphore" kindref="compound">tf::Semaphore</ref> object starts with an initial count. As long as that count is above 0, tasks can acquire the semaphore and do their work. If the count is 0 or less, a task trying to acquire the semaphore will not run but goes to a waiting list of that semaphore. When the semaphore is released by another task, it reschedules all tasks on that waiting list.</para>
<para><programlisting filename=".cpp"><codeline><highlight class="normal"><ref refid="classtf_1_1Executor" kindref="compound">tf::Executor</ref><sp/>executor(8);<sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>create<sp/>an<sp/>executor<sp/>of<sp/>8<sp/>workers</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><ref refid="classtf_1_1Taskflow" kindref="compound">tf::Taskflow</ref><sp/>taskflow;</highlight></codeline>
<codeline><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><ref refid="classtf_1_1Semaphore" kindref="compound">tf::Semaphore</ref><sp/>semaphore(1);<sp/></highlight><highlight class="comment">//<sp/>create<sp/>a<sp/>semaphore<sp/>with<sp/>initial<sp/>count<sp/>1</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><ref refid="cpp/container/vector" kindref="compound" external="/Users/twhuang/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml">std::vector&lt;tf::Task&gt;</ref><sp/>tasks<sp/>{</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/>taskflow.<ref refid="classtf_1_1FlowBuilder_1a60d7a666cab71ecfa3010b2efb0d6b57" kindref="member">emplace</ref>([](){<sp/><ref refid="cpp/io/basic_ostream" kindref="compound" external="/Users/twhuang/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml">std::cout</ref><sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;A&quot;</highlight><highlight class="normal"><sp/>&lt;&lt;<sp/><ref refid="cpp/io/manip/endl" kindref="compound" external="/Users/twhuang/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml">std::endl</ref>;<sp/>}),</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/>taskflow.<ref refid="classtf_1_1FlowBuilder_1a60d7a666cab71ecfa3010b2efb0d6b57" kindref="member">emplace</ref>([](){<sp/>std::cout<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;B&quot;</highlight><highlight class="normal"><sp/>&lt;&lt;<sp/>std::endl;<sp/>}),</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/>taskflow.<ref refid="classtf_1_1FlowBuilder_1a60d7a666cab71ecfa3010b2efb0d6b57" kindref="member">emplace</ref>([](){<sp/><ref refid="cpp/io/basic_ostream" kindref="compound" external="/Users/twhuang/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml">std::cout</ref><sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;C&quot;</highlight><highlight class="normal"><sp/>&lt;&lt;<sp/><ref refid="cpp/io/manip/endl" kindref="compound" external="/Users/twhuang/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml">std::endl</ref>;<sp/>}),</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/>taskflow.<ref refid="classtf_1_1FlowBuilder_1a60d7a666cab71ecfa3010b2efb0d6b57" kindref="member">emplace</ref>([](){<sp/>std::cout<sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;D&quot;</highlight><highlight class="normal"><sp/>&lt;&lt;<sp/>std::endl;<sp/>}),</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/>taskflow.<ref refid="classtf_1_1FlowBuilder_1a60d7a666cab71ecfa3010b2efb0d6b57" kindref="member">emplace</ref>([](){<sp/><ref refid="cpp/io/basic_ostream" kindref="compound" external="/Users/twhuang/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml">std::cout</ref><sp/>&lt;&lt;<sp/></highlight><highlight class="stringliteral">&quot;E&quot;</highlight><highlight class="normal"><sp/>&lt;&lt;<sp/><ref refid="cpp/io/manip/endl" kindref="compound" external="/Users/twhuang/Code/taskflow/doxygen/cppreference-doxygen-web.tag.xml">std::endl</ref>;<sp/>})</highlight></codeline>
<codeline><highlight class="normal">};</highlight></codeline>
<codeline><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"></highlight><highlight class="keywordflow">for</highlight><highlight class="normal">(</highlight><highlight class="keyword">auto</highlight><highlight class="normal"><sp/>&amp;<sp/>task<sp/>:<sp/>tasks)<sp/>{<sp/><sp/></highlight><highlight class="comment">//<sp/>each<sp/>task<sp/>acquires<sp/>and<sp/>release<sp/>the<sp/>semaphore</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/>task.<ref refid="classtf_1_1Task_1a076ab9c6f3a0346e16cfb5fee7dc4ce8" kindref="member">acquire</ref>(semaphore);</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/>task.<ref refid="classtf_1_1Task_1a26709523eb112f2d024f4c0e9d2f0019" kindref="member">release</ref>(semaphore);</highlight></codeline>
<codeline><highlight class="normal">}</highlight></codeline>
<codeline><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal">executor.run(taskflow).wait();</highlight></codeline>
</programlisting></para>
<para>The above example creates five tasks with no dependencies between them. Under normal circumstances, the five tasks would be executed concurrently. However, this example has a semaphore with initial count 1, and all tasks need to acquire that semaphore before running and release that semaphore after they are done. This arrangement limits the number of concurrently running tasks to only one. </para>
    </detaileddescription>
    <inheritancegraph>
      <node id="2">
        <label>tf::CriticalSection</label>
        <link refid="classtf_1_1CriticalSection"/>
        <childnode refid="1" relation="public-inheritance">
        </childnode>
      </node>
      <node id="1">
        <label>tf::Semaphore</label>
        <link refid="classtf_1_1Semaphore"/>
      </node>
    </inheritancegraph>
    <location file="/Users/twhuang/Code/taskflow/taskflow/core/semaphore.hpp" line="68" column="1" bodyfile="/Users/twhuang/Code/taskflow/taskflow/core/semaphore.hpp" bodystart="68" bodyend="102"/>
    <listofallmembers>
      <member refid="classtf_1_1Semaphore_1a385c4e1622677e20bb53b01c8eb85e9b" prot="private" virt="non-virtual"><scope>tf::Semaphore</scope><name>_counter</name></member>
      <member refid="classtf_1_1Semaphore_1a329424188b5287ca596f1af3f6db58f1" prot="private" virt="non-virtual"><scope>tf::Semaphore</scope><name>_mtx</name></member>
      <member refid="classtf_1_1Semaphore_1a47b8ed63d5deecb0878a0b9cc99da20e" prot="private" virt="non-virtual"><scope>tf::Semaphore</scope><name>_release</name></member>
      <member refid="classtf_1_1Semaphore_1aeb12ad1db7794e13829a0a62549d157b" prot="private" virt="non-virtual"><scope>tf::Semaphore</scope><name>_try_acquire_or_wait</name></member>
      <member refid="classtf_1_1Semaphore_1ab05d171c0852d2c6584d62de004f52fb" prot="private" virt="non-virtual"><scope>tf::Semaphore</scope><name>_waiters</name></member>
      <member refid="classtf_1_1Semaphore_1a8e4236750edd903ec0492231076ba2ba" prot="public" virt="non-virtual"><scope>tf::Semaphore</scope><name>count</name></member>
      <member refid="classtf_1_1Semaphore_1a6db9d28bd448a131448276ee03de1e6d" prot="private" virt="non-virtual"><scope>tf::Semaphore</scope><name>Node</name></member>
      <member refid="classtf_1_1Semaphore_1a70ffe5c1611dba350d105b70377f8cd2" prot="public" virt="non-virtual"><scope>tf::Semaphore</scope><name>Semaphore</name></member>
    </listofallmembers>
  </compounddef>
</doxygen>
