<p>代码如下:</p> <pre class="csharpcode">AppDataPromulgator *pThis = (AppDataPromulgator *)arg; HANDLE eventHandeArr[2] = { pThis->m_exitDistributeRealData, s_realDataTransParam.updataEvent }; <span class="kwrd">while</span> ( 1 ) { DWORD ret = ::WaitForMultipleObjects( 2, eventHandeArr, FALSE, INFINITE ); <span class="kwrd">if</span> ( WAIT_OBJECT_0 == ret ) { <span class="kwrd">break</span>; } <span class="kwrd">else</span> <span class="kwrd">if</span> ( WAIT_OBJECT_0+1 == ret ) { <span class="kwrd">if</span> (NULL == s_realDataTransParam.CurrFreq) { <span class="kwrd">continue</span>; } DWORD freqTemp = *(s_realDataTransParam.CurrFreq); <span class="kwrd">float</span> currFreq = <span class="kwrd">float</span>(FREQ_FACTOR) / <span class="kwrd">float</span>(freqTemp+1); <span class="kwrd">if</span>( currFreq < MIN_FREQ || currFreq > MAX_FREQ ) { currFreq = 0.0f; } pThis->DistributeRealData( s_realDataTransParam.pRecData, currFreq ); } } RETAILMSG( 1, (_T(<span class="str">" AppDataPromulgator::RealDataDistributeThread() Exit\r\n"</span>) ) ); <span class="kwrd">return</span> 0;</pre> <style type="text/css"> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }</style>
<p>其错误原因主要如下:</p>
<p>当s_realDataTransParam.updataEvent 为无效值时,则WaitForMultipleObjects()既不会返回WAIT_OBJECT_0也不会返回WAIT_OBJECT_0+1,则当出现该类情况时,则会一直运行while(1)循环,而造成该线程持续占用CPU而导致应用程序启动过慢或者根本无法启动</p>
来源:oschina
链接:https://my.oschina.net/u/180589/blog/160126