Note that there are some explanatory texts on larger screens.

plurals
  1. POThread on Windows
    primarykey
    data
    text
    <p>I have a small question about threading in Windows. I have the following code :</p> <p>main.cpp</p> <pre><code>int main(int ac, char **av) { std::vector&lt;Mthread *&gt; mythread; std::list&lt;std::string&gt; stack; DWORD id = 0; stack.push_back("Maison"); stack.push_back("Femmes"); stack.push_back("Fetes"); stack.push_back("Voitures"); stack.push_back("Nounours"); while (id != 5) { mythread.push_back(new Mthread()); mythread[mythread.size() - 1]-&gt;initThread(&amp;stack, id); id++; } id = 0; while (id != 5) { WaitForInputIdle(mythread[id]-&gt;getThread(), INFINITE); id++; } return (1); } </code></pre> <p>and Mthread.cpp who is creating my <code>Mthread</code> class.</p> <pre><code>Mthread::Mthread() {} Mthread::~Mthread() {} HANDLE Mthread::getThread(void) const { return (this-&gt;thread); } bool Mthread::initThread(std::list&lt;std::string&gt; *list, DWORD ID) { this-&gt;save = list; this-&gt;thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Mthread::ThreadFunc, (LPVOID)list, 0, &amp;ID); if (this-&gt;thread == NULL) { std::cout &lt;&lt; "Erreur lors du lancement du thread" &lt;&lt; std::endl; return (false); } else { return (true); } } void Mthread::ThreadFunc(LPVOID list) { std::cout &lt;&lt; " is launch" &lt;&lt; std::endl; } </code></pre> <p>The code is working, but I have a small problem : no string is written on the terminal. But, if I change my code to :</p> <pre><code>bool Mthread::initThread(std::list&lt;std::string&gt; *list, DWORD ID) { this-&gt;save = list; this-&gt;thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Mthread::ThreadFunc, (LPVOID)list, 0, &amp;ID); if (this-&gt;thread == NULL) { std::cout &lt;&lt; "Erreur lors du lancement du thread" &lt;&lt; std::endl; return (false); } else { std::cout &lt;&lt; "OK" &lt;&lt; std::endl; return (true); } } </code></pre> <p>Well "OK" and "is launch" is written 5 times on the terminal. I don't understand why. When I pass a small string a to <code>cout</code> it seems to be working, but when I don't nothing is written.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload