<?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[Threadklasse programmieren mit Posix Threads]]></title><description><![CDATA[<p>Guten Abend,</p>
<p>Ich habe mich mal an einer eigenen Threadklasse probiert. Klappt soweit auch mal alles.<br />
Allerdings bin ich mir nicht im klaren darüber, welchen Zweck die Funktion pthread_detach hat, und wann ich sie brauche, bzw ob ich sie überhaupt brauche. Ich habe schon unzählige Dokus durchwühlt, aber ich verstehe es einfach nicht.</p>
<p>Meine Klasse sieht im Moment so aus:</p>
<pre><code class="language-cpp">class Thread
{
    pthread_t tid;
    void(*func)();

    static void* thread_func(void* t)
    {
        Thread* thr = static_cast&lt;Thread*&gt;(t);
        thr-&gt;func();
        return 0;
    }

public:

    Thread(void(*function)()) : func(function)
    {
        pthread_create(&amp;tid, 0, &amp;Thread::thread_func, this);
        pthread_detach(tid);
    }

    ~Thread() { pthread_kill(tid, 0); }

    void join()
    {
        pthread_join(tid, 0);
    }
};
</code></pre>
<p>Grüße,<br />
PI</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/285509/threadklasse-programmieren-mit-posix-threads</link><generator>RSS for Node</generator><lastBuildDate>Fri, 21 Aug 2026 08:54:12 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/285509.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 21 Apr 2011 22:38:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Threadklasse programmieren mit Posix Threads on Thu, 21 Apr 2011 22:38:00 GMT]]></title><description><![CDATA[<p>Guten Abend,</p>
<p>Ich habe mich mal an einer eigenen Threadklasse probiert. Klappt soweit auch mal alles.<br />
Allerdings bin ich mir nicht im klaren darüber, welchen Zweck die Funktion pthread_detach hat, und wann ich sie brauche, bzw ob ich sie überhaupt brauche. Ich habe schon unzählige Dokus durchwühlt, aber ich verstehe es einfach nicht.</p>
<p>Meine Klasse sieht im Moment so aus:</p>
<pre><code class="language-cpp">class Thread
{
    pthread_t tid;
    void(*func)();

    static void* thread_func(void* t)
    {
        Thread* thr = static_cast&lt;Thread*&gt;(t);
        thr-&gt;func();
        return 0;
    }

public:

    Thread(void(*function)()) : func(function)
    {
        pthread_create(&amp;tid, 0, &amp;Thread::thread_func, this);
        pthread_detach(tid);
    }

    ~Thread() { pthread_kill(tid, 0); }

    void join()
    {
        pthread_join(tid, 0);
    }
};
</code></pre>
<p>Grüße,<br />
PI</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2052725</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2052725</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Thu, 21 Apr 2011 22:38:00 GMT</pubDate></item><item><title><![CDATA[Reply to Threadklasse programmieren mit Posix Threads on Thu, 21 Apr 2011 22:44:06 GMT]]></title><description><![CDATA[<p>Wenn du pthread_detach nicht aufrufst, werden die Ressourcen für den Thread auch nach dessen Beendigung nicht freigegeben.<br />
Wenn du häufig Threads startest, müllst du also ziemlich schnell den Speicher zu.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2052730</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2052730</guid><dc:creator><![CDATA[Athar]]></dc:creator><pubDate>Thu, 21 Apr 2011 22:44:06 GMT</pubDate></item></channel></rss>