<?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[Fehler bei Parameterübergabe an Thread]]></title><description><![CDATA[<p>Hallo,<br />
ich habe mal wieder ein Problem.<br />
Ich habe einen neuen Datentyp definiert, mit dem ich die Parameter an meinen Thread übergeben will.</p>
<pre><code class="language-cpp">//Struct für die Parameter, die an den KI-Thread übergeben werden
typedef struct{
    HWND hwnd;
    int iFeldZust[ANZSPALTEN][MAXSTEINE];
}PARAMS, *PPARAMS;
</code></pre>
<p>Vor der Übergabe an den Thread weise ich den Variablen ihre werte zu und gebe das Feld aus</p>
<pre><code class="language-cpp">params.hwnd=hwnd;
            for(int i=0; i&lt;ANZSPALTEN; i++)
            {
                for(int j=0; j&lt;MAXSTEINE; j++)
                {
                    params.iFeldZust[i][j]=iFeldZust[i][j];
                }
            }

            for(int i=0; i&lt;ANZSPALTEN; i++)
            {
                std::cout &lt;&lt; endl;
                for(int j=0; j&lt;MAXSTEINE; j++)
                {

                    std::cout &lt;&lt; params.iFeldZust[i][j];
                }
            }
            std::cout &lt;&lt; endl;
            bKIAktiv=true;
            _beginthread(Thread,0,&amp;params);
</code></pre>
<p>Im gestarteten Thread gebe ich das Feld nochmal aus, nur ist dabei das Feld fehlerhaft.</p>
<pre><code class="language-cpp">KI ki;
    PPARAMS pparams = (PPARAMS) pvoid;

    for(int i=0; i&lt;ANZSPALTEN; i++)
    {
        std::cout &lt;&lt; endl;
        for(int j=0; j&lt;MAXSTEINE; j++)
        {

            std::cout &lt;&lt; pparams-&gt;iFeldZust[i][j];
        }
    }
</code></pre>
<p>Die Ausgabe sieht so aus</p>
<pre><code>000000
000000
000000
100000
000000
000000
000000

000000
000000
000000
100000
000000
000000
042037960000
</code></pre>
<p>Wenn ihr noch Informationen braucht, einfach Fragen.<br />
Schon mal danke für die Hilfe<br />
Held</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/184971/fehler-bei-parameterübergabe-an-thread</link><generator>RSS for Node</generator><lastBuildDate>Sun, 05 Jul 2026 16:08:46 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/184971.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 20 Jun 2007 17:44:44 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Fehler bei Parameterübergabe an Thread on Wed, 20 Jun 2007 17:44:44 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich habe mal wieder ein Problem.<br />
Ich habe einen neuen Datentyp definiert, mit dem ich die Parameter an meinen Thread übergeben will.</p>
<pre><code class="language-cpp">//Struct für die Parameter, die an den KI-Thread übergeben werden
typedef struct{
    HWND hwnd;
    int iFeldZust[ANZSPALTEN][MAXSTEINE];
}PARAMS, *PPARAMS;
</code></pre>
<p>Vor der Übergabe an den Thread weise ich den Variablen ihre werte zu und gebe das Feld aus</p>
<pre><code class="language-cpp">params.hwnd=hwnd;
            for(int i=0; i&lt;ANZSPALTEN; i++)
            {
                for(int j=0; j&lt;MAXSTEINE; j++)
                {
                    params.iFeldZust[i][j]=iFeldZust[i][j];
                }
            }

            for(int i=0; i&lt;ANZSPALTEN; i++)
            {
                std::cout &lt;&lt; endl;
                for(int j=0; j&lt;MAXSTEINE; j++)
                {

                    std::cout &lt;&lt; params.iFeldZust[i][j];
                }
            }
            std::cout &lt;&lt; endl;
            bKIAktiv=true;
            _beginthread(Thread,0,&amp;params);
</code></pre>
<p>Im gestarteten Thread gebe ich das Feld nochmal aus, nur ist dabei das Feld fehlerhaft.</p>
<pre><code class="language-cpp">KI ki;
    PPARAMS pparams = (PPARAMS) pvoid;

    for(int i=0; i&lt;ANZSPALTEN; i++)
    {
        std::cout &lt;&lt; endl;
        for(int j=0; j&lt;MAXSTEINE; j++)
        {

            std::cout &lt;&lt; pparams-&gt;iFeldZust[i][j];
        }
    }
</code></pre>
<p>Die Ausgabe sieht so aus</p>
<pre><code>000000
000000
000000
100000
000000
000000
000000

000000
000000
000000
100000
000000
000000
042037960000
</code></pre>
<p>Wenn ihr noch Informationen braucht, einfach Fragen.<br />
Schon mal danke für die Hilfe<br />
Held</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1310140</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1310140</guid><dc:creator><![CDATA[Held vom Erdbeerfeld]]></dc:creator><pubDate>Wed, 20 Jun 2007 17:44:44 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei Parameterübergabe an Thread on Wed, 20 Jun 2007 19:27:07 GMT]]></title><description><![CDATA[<p>sowas wie 'std::cout' ist nicht von natur aus threadingtauglich, vielleicht liegt's daran?<br />
macht du die zweiter ausgabe erst, wenn die erste beendet ist, oder läuft das parallel?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1310186</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1310186</guid><dc:creator><![CDATA[pale dog]]></dc:creator><pubDate>Wed, 20 Jun 2007 19:27:07 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei Parameterübergabe an Thread on Wed, 20 Jun 2007 19:59:16 GMT]]></title><description><![CDATA[<p>wo legst du params an? auf dem stack oder heap? wenn auf dem stack, kann es sein, dass der pointer im thread auf was ungültiges zeigt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1310202</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1310202</guid><dc:creator><![CDATA[der mit dem code]]></dc:creator><pubDate>Wed, 20 Jun 2007 19:59:16 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler bei Parameterübergabe an Thread on Thu, 21 Jun 2007 18:03:16 GMT]]></title><description><![CDATA[<p>Ich hab params jetzt auf den Heap und es funktioniert einwandfrei.<br />
Danke<br />
Held</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1310938</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1310938</guid><dc:creator><![CDATA[Held vom Erdbeerfeld]]></dc:creator><pubDate>Thu, 21 Jun 2007 18:03:16 GMT</pubDate></item></channel></rss>