<?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[thread hängt bei while]]></title><description><![CDATA[<p>Hey Leute,<br />
Ich habe eine frage zum std::thread.</p>
<p>Wenn ich ein Thread erstelle wie z.B. hier:</p>
<p>std::thread t(meineFunktion);<br />
t.join;</p>
<pre><code>std::thread t(meineFunktion);
t.join;
</code></pre>
<p>und in der &quot;meineFunktion&quot; ein while statement ist, bleibt mein Programm beim while statement obwohl es doch fortfahren sollte (dennoch das while statement ausfführen muss)</p>
<pre><code>while(true)
{
...
}
</code></pre>
<p>Freue mich auf jede Antwort</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/331817/thread-hängt-bei-while</link><generator>RSS for Node</generator><lastBuildDate>Fri, 01 May 2026 08:10:52 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/331817.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 21 Mar 2015 18:21:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to thread hängt bei while on Sat, 21 Mar 2015 18:21:43 GMT]]></title><description><![CDATA[<p>Hey Leute,<br />
Ich habe eine frage zum std::thread.</p>
<p>Wenn ich ein Thread erstelle wie z.B. hier:</p>
<p>std::thread t(meineFunktion);<br />
t.join;</p>
<pre><code>std::thread t(meineFunktion);
t.join;
</code></pre>
<p>und in der &quot;meineFunktion&quot; ein while statement ist, bleibt mein Programm beim while statement obwohl es doch fortfahren sollte (dennoch das while statement ausfführen muss)</p>
<pre><code>while(true)
{
...
}
</code></pre>
<p>Freue mich auf jede Antwort</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2447555</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2447555</guid><dc:creator><![CDATA[reba]]></dc:creator><pubDate>Sat, 21 Mar 2015 18:21:43 GMT</pubDate></item><item><title><![CDATA[Reply to thread hängt bei while on Sat, 21 Mar 2015 18:59:39 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>was hängt, bzw.was soll deiner Meinung nach 'fortfahren'?</p>
<p>Thread hängt endlos im while(true) und der main-thread wartet (join) auf den Thread.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2447563</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2447563</guid><dc:creator><![CDATA[Jockelx]]></dc:creator><pubDate>Sat, 21 Mar 2015 18:59:39 GMT</pubDate></item><item><title><![CDATA[Reply to thread hängt bei while on Sat, 21 Mar 2015 19:04:27 GMT]]></title><description><![CDATA[<p>Also ich wollte eigentlich einen Listener erstellen und das Programm sollte die while schleife in den Hintergrund stecken damit imputs weiterhin funktionieren ansonsten bleibt ja das Programm in der while schleife stecken.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2447564</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2447564</guid><dc:creator><![CDATA[reba]]></dc:creator><pubDate>Sat, 21 Mar 2015 19:04:27 GMT</pubDate></item><item><title><![CDATA[Reply to thread hängt bei while on Sat, 21 Mar 2015 19:56:16 GMT]]></title><description><![CDATA[<p>Warum dann join?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2447565</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2447565</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Sat, 21 Mar 2015 19:56:16 GMT</pubDate></item><item><title><![CDATA[Reply to thread hängt bei while on Sat, 21 Mar 2015 20:01:26 GMT]]></title><description><![CDATA[<p>Dadurch stürtz mien Programm ab</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2447566</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2447566</guid><dc:creator><![CDATA[reba]]></dc:creator><pubDate>Sat, 21 Mar 2015 20:01:26 GMT</pubDate></item><item><title><![CDATA[Reply to thread hängt bei while on Sat, 21 Mar 2015 20:39:01 GMT]]></title><description><![CDATA[<p>reba schrieb:</p>
<blockquote>
<p>Dadurch stürtz mien Programm ab</p>
</blockquote>
<p>Das soll wohl heißen, dadurch stürzt es nicht ab.</p>
<p>Du musst dem Thread sagen, das er die Schleife beenden soll, und erst dann warten:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;chrono&gt;
#include &lt;thread&gt;
#include &lt;atomic&gt;

int main()
{
  using namespace std::literals;

  std::atomic&lt;bool&gt; run{ true };

  std::thread t{ [&amp;]{
      while( run ) {
        // hier was tun
        std::this_thread::sleep_for(2s);
        std::cerr &lt;&lt; &quot;Thread\n&quot;;
      }
  }};

  // hier was tun
  std::cerr &lt;&lt; &quot;main schläft\n&quot;;
  std::this_thread::sleep_for(20s);
  std::cerr &lt;&lt; &quot;main wach\n&quot;;

  // habe fertig, thread beenden
  run = false;
  t.join();

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2447568</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2447568</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Sat, 21 Mar 2015 20:39:01 GMT</pubDate></item></channel></rss>