<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[herausfinden, ob ein std::thread noch läuft]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>gibt es eine Möglichkeit, herauszufinden, ob ein std::thread noch läuft ohne ihn zu joinen?</p>
<p>Mit g++ 4.7.2 hab ich folgendes getestet:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;thread&gt;
#include &lt;chrono&gt;
void foo()
{
    std::this_thread::sleep_for(std::chrono::seconds(1));
    std::cout &lt;&lt; &quot;The thread is done.&quot; &lt;&lt; '\n';
}
int main()
{
    std::thread t;
    std::cout &lt;&lt; &quot;before starting, joinable: &quot; &lt;&lt; t.joinable() &lt;&lt; '\n';
    t = std::thread(foo);
    std::cout &lt;&lt; &quot;after starting, joinable: &quot; &lt;&lt; t.joinable() &lt;&lt; '\n';
    std::this_thread::sleep_for(std::chrono::seconds(2));
    std::cout &lt;&lt; &quot;after finishing, joinable: &quot; &lt;&lt; t.joinable() &lt;&lt; '\n';
    t.join();
    std::cout &lt;&lt; &quot;after joining, joinable: &quot; &lt;&lt; t.joinable() &lt;&lt; '\n';
}
</code></pre>
<p>Ausgabe:</p>
<pre><code>before starting, joinable: 0
after starting, joinable: 1
The thread is done.
after finishing, joinable: 1
after joining, joinable: 0
</code></pre>
<p>Kann man schon im Beispiel bei &quot;after finishing&quot; herausfinden, ob das t.join(); danach dauern wird, oder direkt returned, weil eh schon alles vorbei ist?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/309390/herausfinden-ob-ein-std-thread-noch-läuft</link><generator>RSS for Node</generator><lastBuildDate>Wed, 05 Aug 2026 16:36:26 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/309390.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 22 Oct 2012 08:11:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to herausfinden, ob ein std::thread noch läuft on Mon, 22 Oct 2012 08:11:52 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>gibt es eine Möglichkeit, herauszufinden, ob ein std::thread noch läuft ohne ihn zu joinen?</p>
<p>Mit g++ 4.7.2 hab ich folgendes getestet:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;thread&gt;
#include &lt;chrono&gt;
void foo()
{
    std::this_thread::sleep_for(std::chrono::seconds(1));
    std::cout &lt;&lt; &quot;The thread is done.&quot; &lt;&lt; '\n';
}
int main()
{
    std::thread t;
    std::cout &lt;&lt; &quot;before starting, joinable: &quot; &lt;&lt; t.joinable() &lt;&lt; '\n';
    t = std::thread(foo);
    std::cout &lt;&lt; &quot;after starting, joinable: &quot; &lt;&lt; t.joinable() &lt;&lt; '\n';
    std::this_thread::sleep_for(std::chrono::seconds(2));
    std::cout &lt;&lt; &quot;after finishing, joinable: &quot; &lt;&lt; t.joinable() &lt;&lt; '\n';
    t.join();
    std::cout &lt;&lt; &quot;after joining, joinable: &quot; &lt;&lt; t.joinable() &lt;&lt; '\n';
}
</code></pre>
<p>Ausgabe:</p>
<pre><code>before starting, joinable: 0
after starting, joinable: 1
The thread is done.
after finishing, joinable: 1
after joining, joinable: 0
</code></pre>
<p>Kann man schon im Beispiel bei &quot;after finishing&quot; herausfinden, ob das t.join(); danach dauern wird, oder direkt returned, weil eh schon alles vorbei ist?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2262707</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2262707</guid><dc:creator><![CDATA[Dobi]]></dc:creator><pubDate>Mon, 22 Oct 2012 08:11:52 GMT</pubDate></item><item><title><![CDATA[Reply to herausfinden, ob ein std::thread noch läuft on Mon, 22 Oct 2012 08:41:55 GMT]]></title><description><![CDATA[<p>Setze ein Flag per Hand. Das C++ bietet nur einen kleinen gemeinsamen Nenner zwischen den Betriebssystem als Interface. Aber du moechtest wahrscheinlich keinen Thread sondern eher Future oder Promise.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2262725</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2262725</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Mon, 22 Oct 2012 08:41:55 GMT</pubDate></item><item><title><![CDATA[Reply to herausfinden, ob ein std::thread noch läuft on Mon, 22 Oct 2012 10:44:36 GMT]]></title><description><![CDATA[<p>OK, thx.<br />
(Trotzdem doof, so. ;))</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2262797</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2262797</guid><dc:creator><![CDATA[Dobi]]></dc:creator><pubDate>Mon, 22 Oct 2012 10:44:36 GMT</pubDate></item></channel></rss>