Multithreading Multi-Threaded Programming
Multithreading Multi-Threaded Programming
Multithreading Multi-Threaded Programming
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
How the Main Thread Talks to a Worker<br />
Thread<br />
} Does not work: Windows message sent to the worker<br />
} the worker thread doesn’t have a message loop.<br />
} What work:<br />
} global variables : The simplest way, because all the threads in the<br />
process have access to all the globals.<br />
} More , wait…<br />
17<br />
UINT ComputeThreadProc(LPVOID pParam)<br />
{<br />
g_nCount = 0;<br />
while (g_nCount < 100) {<br />
// Do some computation here<br />
::InterlockedIncrement((long*) &g_nCount);<br />
}<br />
return 0;<br />
}<br />
Advanced Windows Network <strong>Programming</strong><br />
11/11/12