<?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[Wie kann ich bei Boost-Threads Variablen übergeben?]]></title><description><![CDATA[<p>Ich habe eine Funktion:</p>
<p><em>void threadFun(int a,int b)<br />
{<br />
printf(&quot;%i %i&quot;a,b);<br />
}</em></p>
<p>diese rufe ich als Boost-Thread wie folgt auf:</p>
<p>*int main()<br />
{<br />
int a=1,b=2;</p>
<p>boost::thread_group grp;<br />
grp.create_thread(threadFun(a,b));<br />
boost::thread::yield();<br />
grp.join_all();</p>
<p>return 0;<br />
}*<br />
Folgende Fehlermeldung beim Kompilieren:</p>
<p><em>invalid use of void expression</em></p>
<p>für die in der ich den Thread aufrufe ( <em>grp.create_thread(threadFun(a,b));</em> )<br />
Vielleicht kennt sich jemand aus und kann mir sagen was ich falsch mache. Mit dem Aufruf <em>grp.create_thread(threadFun,a,b)</em> hab ich es übrigens auch schon versucht.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/250030/wie-kann-ich-bei-boost-threads-variablen-übergeben</link><generator>RSS for Node</generator><lastBuildDate>Wed, 16 Sep 2026 05:09:24 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/250030.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 15 Sep 2009 13:53:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Wie kann ich bei Boost-Threads Variablen übergeben? on Tue, 15 Sep 2009 13:53:06 GMT]]></title><description><![CDATA[<p>Ich habe eine Funktion:</p>
<p><em>void threadFun(int a,int b)<br />
{<br />
printf(&quot;%i %i&quot;a,b);<br />
}</em></p>
<p>diese rufe ich als Boost-Thread wie folgt auf:</p>
<p>*int main()<br />
{<br />
int a=1,b=2;</p>
<p>boost::thread_group grp;<br />
grp.create_thread(threadFun(a,b));<br />
boost::thread::yield();<br />
grp.join_all();</p>
<p>return 0;<br />
}*<br />
Folgende Fehlermeldung beim Kompilieren:</p>
<p><em>invalid use of void expression</em></p>
<p>für die in der ich den Thread aufrufe ( <em>grp.create_thread(threadFun(a,b));</em> )<br />
Vielleicht kennt sich jemand aus und kann mir sagen was ich falsch mache. Mit dem Aufruf <em>grp.create_thread(threadFun,a,b)</em> hab ich es übrigens auch schon versucht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1778850</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1778850</guid><dc:creator><![CDATA[timobachtel]]></dc:creator><pubDate>Tue, 15 Sep 2009 13:53:06 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann ich bei Boost-Threads Variablen übergeben? on Tue, 15 Sep 2009 13:57:18 GMT]]></title><description><![CDATA[<p>guck mal - hier gibts cpp-tags:</p>
<pre><code class="language-cpp">void threadFun(int a, int b)
{ 
  std::cout &lt;&lt; a &lt;&lt; ' ' &lt;&lt; b;
} 

int main() 
{ 
  int a=1, b=2; 

  boost::thread_group grp; 
  grp.create_thread(threadFun(a,b)); 
  boost::thread::yield(); 
  grp.join_all(); 
}
</code></pre>
<p>da ich allerdings keinen plan von boost::thread hab, belass ichs mal dabei, die cpp-tags eingefügt zu haben ;P</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1778851</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1778851</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Tue, 15 Sep 2009 13:57:18 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann ich bei Boost-Threads Variablen übergeben? on Tue, 15 Sep 2009 14:06:33 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">grp.create_thread(boost::bind(threadFun, a, b));
// oder
grp.add_thread(new boost::thread(threadFun, a, b));
</code></pre>
<p>Ich hab zwar keine Ahnung von boost.thread, aber ein kurzer Blick in die Doku hat mir das geliefert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1778857</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1778857</guid><dc:creator><![CDATA[Ryuzaki]]></dc:creator><pubDate>Tue, 15 Sep 2009 14:06:33 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann ich bei Boost-Threads Variablen übergeben? on Tue, 15 Sep 2009 14:49:17 GMT]]></title><description><![CDATA[<p>Danke, läuft.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1778878</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1778878</guid><dc:creator><![CDATA[timobachtel]]></dc:creator><pubDate>Tue, 15 Sep 2009 14:49:17 GMT</pubDate></item><item><title><![CDATA[Reply to Wie kann ich bei Boost-Threads Variablen übergeben? on Tue, 15 Sep 2009 14:52:26 GMT]]></title><description><![CDATA[<p>Aus der Doku:</p>
<blockquote>
<p>Thread Constructor</p>
<p>template&lt;typename Callable&gt;<br />
thread(Callable func);</p>
<p>Preconditions:</p>
<p>Callable must by copyable.<br />
Effects:</p>
<p>func is copied into storage managed internally by the thread library, and that copy is invoked on a newly-created thread of execution. If this invocation results in an exception being propagated into the internals of the thread library that is not of type boost::thread_interrupted, then std::terminate() will be called.</p>
</blockquote>
<p>Man erstellt eine neue Klasse mit Member, ueberlaedt den operator()() und greift in diesem auf die Member zu.</p>
<p>Moeglichkeiten gibt es viele ...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1778879</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1778879</guid><dc:creator><![CDATA[knivil]]></dc:creator><pubDate>Tue, 15 Sep 2009 14:52:26 GMT</pubDate></item></channel></rss>