mincheat 2014-05-05 05:51 采纳率: 0%
浏览 2316

线程消息队列的宽度问题

想知道windows下系统消息队列的大小,线程消息队列的大小,在网上找了下,据说线程消息队列默认只有可以保存8个消息。我自己做了下测试,如下
void CMainFrame::HandleWaitThread(LPVOID lParam)
{

MSG msg;

Sleep(30000);
while (true)
{
    if(GetMessage(&msg,0,0,0)) //get msg from message queue
    {
        TRACE(_T("wait              msg.message = %d\r\n"),msg.message);
    }
}

}

void CMainFrame::HandleSendThread(LPVOID lParam)
{
ASSERT(lParam);
CMainFrame* pDlg = reinterpret_cast(lParam);
while(1)
{
static long i = 0;
TRACE(_T("send msg.message = %d\r\n"),i);
pDlg->pWaitThread->PostThreadMessage(i,0,0);
i++;
Sleep(500);
}
}
send线程向wait线程不断post消息,一开始wait线程Sleep 30s,那么这短时间send线程发送了60次消息,30s后,wait线程还是可以把那60个消息打印出来,这就应该可以说明线程消息队列不只存8个了吧。另外,在测试的时候还发现一个问题,每次测试都会有wait线程丢失消息的现象,就是说总会有几个消息打印不出来(或者说没有接收到),这到底是怎么回事,请各位大神帮忙看看,3q

  • 写回答

1条回答 默认 最新

  • Eleven 2014-11-07 10:59
    关注

    MSDN上有说明:

    Windows 2000/XP: There is a limit of 10,000 posted messages per message queue. This limit should be sufficiently large. If your application exceeds the limit, it should be redesigned to avoid consuming so many system resources. To adjust this limit, modify the following registry key.

    HKEY_LOCAL_MACHINE
    SOFTWARE
    Microsoft
    Windows NT
    CurrentVersion
    Windows
    USERPostMessageLimit
    The minimum acceptable value is 4000.

    评论

报告相同问题?