<?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 frage]]></title><description><![CDATA[<p>hi,</p>
<p>ich habe eine klassenmethode in der ich über einen bestimmten zeitraum eine gewisse anzahl threads am laufen haben möchte die alle das gleiche tun.</p>
<pre><code>void Handler::start(std::size_t request_amount, std::size_t minutes)
{
	using namespace std::chrono;

	system_clock::time_point timepoint = system_clock::now();
	std::vector&lt;std::thread&gt; threadpool(request_amount);

	while (timepoint.time_since_epoch().count() * system_clock::period::num / system_clock::period::den &lt; minutes * 60)
	{
		for (std::size_t i = 0; i &lt; threadpool.size(); ++i)
		{
			threadpool[i] = std::thread(&amp;Handler::execute, this);
			threadpool[i].detach();
		}
	}
}
</code></pre>
<p>Jetzt möchte ich, dass wenn ein Thread fertig ist dieser &quot;erneuert&quot; wird. Wie kann ich feststellen ob der mit detach() modifizierte Thread fertig ist?</p>
<p>Grüße</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/326725/thread-frage</link><generator>RSS for Node</generator><lastBuildDate>Tue, 26 May 2026 10:54:17 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/326725.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 04 Jul 2014 08:19:49 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to thread frage on Fri, 04 Jul 2014 08:19:49 GMT]]></title><description><![CDATA[<p>hi,</p>
<p>ich habe eine klassenmethode in der ich über einen bestimmten zeitraum eine gewisse anzahl threads am laufen haben möchte die alle das gleiche tun.</p>
<pre><code>void Handler::start(std::size_t request_amount, std::size_t minutes)
{
	using namespace std::chrono;

	system_clock::time_point timepoint = system_clock::now();
	std::vector&lt;std::thread&gt; threadpool(request_amount);

	while (timepoint.time_since_epoch().count() * system_clock::period::num / system_clock::period::den &lt; minutes * 60)
	{
		for (std::size_t i = 0; i &lt; threadpool.size(); ++i)
		{
			threadpool[i] = std::thread(&amp;Handler::execute, this);
			threadpool[i].detach();
		}
	}
}
</code></pre>
<p>Jetzt möchte ich, dass wenn ein Thread fertig ist dieser &quot;erneuert&quot; wird. Wie kann ich feststellen ob der mit detach() modifizierte Thread fertig ist?</p>
<p>Grüße</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2406948</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2406948</guid><dc:creator><![CDATA[threadnweb]]></dc:creator><pubDate>Fri, 04 Jul 2014 08:19:49 GMT</pubDate></item><item><title><![CDATA[Reply to thread frage on Fri, 04 Jul 2014 08:58:42 GMT]]></title><description><![CDATA[<p>Ich bin mir nicht ganz sicher; aber wird der thread mit detach() nicht so etwas wie freigegeben in dem Sinne: mach fertig wenn du kannst und räume dich selbst auf (Ressourcen).<br />
Zitat aus <a href="http://www.ijon.de/comp/tutorials/threads/create.html:" rel="nofollow">http://www.ijon.de/comp/tutorials/threads/create.html:</a>&quot; Ein solcher Thread läuft dann ohne jegliche äußere Kontrolle bis zum Ende. Es gibt von außerhalb keine Möglichkeit, festzustellen, ob er sich schon beendet hat, oder seinen Rückgabewert zu bekommen. Sein Identifier wird ungültig, wenn er sich beendet.&quot;.<br />
Mal so schnell als Idee: Ich würde einen Threadpool von Objekten mit Status und Referenz auf einen Thread bauen. Der Thread könnte dann den Status setzen und über den Threadpool wüsste ich jetzt, wie der Status des referenzierten Threads wäre.<br />
Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2406959</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2406959</guid><dc:creator><![CDATA[Helmut.Jakoby]]></dc:creator><pubDate>Fri, 04 Jul 2014 08:58:42 GMT</pubDate></item><item><title><![CDATA[Reply to thread frage on Fri, 04 Jul 2014 09:04:52 GMT]]></title><description><![CDATA[<p>Möglichkeit 1: Du nimmst ein atomic&lt;bool&gt; pro Thread, das von jedem Handler auf true gesetzt wird, lässt das detach weg (was soll das da eigentlich?) und joinst.<br />
Möglichkeit 2: Du benutzt <a href="http://www.cplusplus.com/reference/thread/thread/native_handle/" rel="nofollow">thread::native_handle</a> und OS-spezifische Funktionen.<br />
Möglichkeit 3: Du benutzt <a href="http://www.cplusplus.com/reference/future/async/" rel="nofollow">async</a> + <a href="http://www.cplusplus.com/reference/future/future/" rel="nofollow">future</a> statt thread und fragt mit <a href="http://www.cplusplus.com/reference/future/future/wait_for/" rel="nofollow">future::wait_for</a> ob der Thread schon fertig ist.</p>
<p>Nichts davon erscheint mir eine gute Lösung. Die korrekte Lösung ist <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3558.pdf" rel="nofollow">future::then</a>, aber das ist noch nicht Standard. Boost 1.55 hat es scheinbar auch noch nicht, <a href="http://www.boost.org/doc/libs/1_55_0/doc/html/thread/future.html" rel="nofollow">soll aber kommen</a>. Du kannst es auch <a href="http://stackoverflow.com/questions/14489935/implementing-futurethen-equivalent-for-asynchronous-execution-in-c11" rel="nofollow">selbst (ab-)schreiben</a>, mit gewissen Mängeln.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2406961</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2406961</guid><dc:creator><![CDATA[nwp3]]></dc:creator><pubDate>Fri, 04 Jul 2014 09:04:52 GMT</pubDate></item></channel></rss>