<?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[pthread argumente]]></title><description><![CDATA[<p>hi ihr,</p>
<p>weiss jemand, wie ich einem thread möglichst einfach beliebige argumente mitgeben kann?<br />
also, beispiel:</p>
<pre><code>#include &lt;pthread.h&gt;
#include &lt;iostream&gt;
using namespace std;

void *funktion( void *a){
cout&lt;&lt;&quot;bla&quot;&lt;&lt;endl;
pthread_exit(NULL);
}

int main(){
int x=1;
pthread_t th1;
pthread_create(&amp;th1, NULL, funktion, &amp;x);
funktion((void*)x);
return 0;
}
</code></pre>
<p>sollte zweimal &quot;bla&quot; ausgeben.<br />
soweit so gut, ich würde aber gerne eine sinnvolle funktion haben(die von einem thread ausgeführt wird), wenigstens eine, der ich strings übergeben kann und integers und so, weiss jemand, wie ich das machen kann? oder z.b. auch auf die eins zugreifen kann, die ja eigtl in x drin ist und die ausgeben kann?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/161053/pthread-argumente</link><generator>RSS for Node</generator><lastBuildDate>Fri, 11 Sep 2026 17:25:58 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/161053.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 02 Oct 2006 18:32:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to pthread argumente on Mon, 02 Oct 2006 18:32:10 GMT]]></title><description><![CDATA[<p>hi ihr,</p>
<p>weiss jemand, wie ich einem thread möglichst einfach beliebige argumente mitgeben kann?<br />
also, beispiel:</p>
<pre><code>#include &lt;pthread.h&gt;
#include &lt;iostream&gt;
using namespace std;

void *funktion( void *a){
cout&lt;&lt;&quot;bla&quot;&lt;&lt;endl;
pthread_exit(NULL);
}

int main(){
int x=1;
pthread_t th1;
pthread_create(&amp;th1, NULL, funktion, &amp;x);
funktion((void*)x);
return 0;
}
</code></pre>
<p>sollte zweimal &quot;bla&quot; ausgeben.<br />
soweit so gut, ich würde aber gerne eine sinnvolle funktion haben(die von einem thread ausgeführt wird), wenigstens eine, der ich strings übergeben kann und integers und so, weiss jemand, wie ich das machen kann? oder z.b. auch auf die eins zugreifen kann, die ja eigtl in x drin ist und die ausgeben kann?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1148227</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1148227</guid><dc:creator><![CDATA[myggel]]></dc:creator><pubDate>Mon, 02 Oct 2006 18:32:10 GMT</pubDate></item><item><title><![CDATA[Reply to pthread argumente on Mon, 02 Oct 2006 19:36:46 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Das was du da als Adresse von x übergibst, bekommst du aus dem Parameter wieder raus-casten.</p>
<pre><code class="language-cpp">#include &lt;pthread.h&gt;
#include &lt;iostream&gt;
using namespace std;

void *funktion( void *a){
int* value = reinterpret_cast&lt;int*&gt;(a);
cout&lt;&lt;*value&lt;&lt;endl;
pthread_exit(NULL);
}

int main(){
int x=1;
pthread_t th1;
pthread_create(&amp;th1, NULL, funktion, &amp;x);
funktion((void*)x);
return 0;
}
</code></pre>
<p>Äquivalent für jeden andern Typ</p>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1148334</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1148334</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Mon, 02 Oct 2006 19:36:46 GMT</pubDate></item><item><title><![CDATA[Reply to pthread argumente on Tue, 03 Oct 2006 10:42:56 GMT]]></title><description><![CDATA[<p>hm, danke askari,</p>
<p>das prob ist jetzt nur noch, dass ich da nen speicherzugriffsfehler bekomm.<br />
thread 1 machts gut, thread zwei nicht.</p>
<pre><code class="language-cpp">#include &lt;pthread.h&gt;
#include &lt;iostream&gt;
using namespace std;

void *funktion( void *a){
int* value = reinterpret_cast&lt;int*&gt;(a);
cout&lt;&lt;*value&lt;&lt;endl;
//pthread_exit(NULL);
}

int main(){
int x=1;
pthread_t th1;
pthread_create(&amp;th1, NULL, funktion, &amp;x);
pthread_join(th1, NULL);
funktion((void*)x);
return 0;
}
</code></pre>
<p>ausgabe:</p>
<pre><code>linux-cctu:~/prgversuche&gt; ./a.out
1
Speicherzugriffsfehler
</code></pre>
<p>was natürlich irgenwie doof ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1148555</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1148555</guid><dc:creator><![CDATA[myggel]]></dc:creator><pubDate>Tue, 03 Oct 2006 10:42:56 GMT</pubDate></item><item><title><![CDATA[Reply to pthread argumente on Tue, 03 Oct 2006 13:50:37 GMT]]></title><description><![CDATA[<p>myggel schrieb:</p>
<blockquote>
<pre><code class="language-cpp">[...]
funktion((void*)x);
return 0;
}
</code></pre>
<p>ausgabe:</p>
</blockquote>
<p>Sicher, dass du nicht funktion((void*)&amp;x); meintest?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1148673</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1148673</guid><dc:creator><![CDATA[HumeSikkins]]></dc:creator><pubDate>Tue, 03 Oct 2006 13:50:37 GMT</pubDate></item><item><title><![CDATA[Reply to pthread argumente on Tue, 03 Oct 2006 16:16:18 GMT]]></title><description><![CDATA[<p>uhmmmm, joa, das ist glaub ganz vernünftig, das mal zu testen. ähm.</p>
<p>danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1148760</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1148760</guid><dc:creator><![CDATA[myggel]]></dc:creator><pubDate>Tue, 03 Oct 2006 16:16:18 GMT</pubDate></item></channel></rss>