⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_36573.htm

📁 vc
💻 HTM
字号:
<p>
序号:36573 发表者:万能万万不能 发表日期:2003-04-16 20:40:53
<br>主题:多线程间通信遇到怪问题.
<br>内容:我的一个线程往另一个线程发消息,接收线程有时会丢消息.<BR>绝对不是线程消息队列溢出.线程也没有结束.<BR><BR>我想问还有其他什么可能会导致这种情况的出现.<BR><BR>我现在没办法,只能通过反复发消息,直到得到收到确认.<BR><BR>请大家多多指教.
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:xiongli 回复日期:2003-04-16 21:39:12
<br>内容:用sendmessage还是postmessage?
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:万能万万不能 回复日期:2003-04-16 22:39:09
<br>内容:用的是::PostThreadMessage(...);<BR>接收线程一般正确都可以收到消息,可有时候好像会丢掉消息.<BR>这个接收线程接收多个线程发来的请求.<BR><BR>不知道在什么情况下会发生收不到消息.<BR><BR>是发的问题 ,还是收的问题.还是有什么没有考虑到的情况会导致该现象的发生.<BR><BR>拜托了.我都困扰了好久了,目前采取了只是零时采取了接收消息后应答确认的缓兵之计.<BR>但没找到根心里不踏实,因为要传递的消息种类太多了,说不定其他消息也会丢,运行时间长了就肯定会出现预想不到问题了.<BR><BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:neilgan 回复日期:2003-04-16 23:50:48
<br>内容:What kind of messages will lost?<BR><BR>For WM_TIMER, there is always at most one instance in the message queue.<BR><BR>For WM_QUIT, it is actually not a message, it is a flag, so there is also only one (at most) instance in the queue.<BR><BR>For other kind of messages, message lost can happen if you send message and the thread doesn't have a message queue ready.<BR><BR>Following is what I quoted from MSDN:<BR><BR>The thread to which the message is posted must have created a message queue, or else the call to PostThreadMessage fails. Use one of the following methods to handle this situation: <BR><BR>Call PostThreadMessage. If it fails, call theSleep function and call PostThreadMessage again. Repeat until PostThreadMessage succeeds. <BR>Create an event object, then create the thread. Use theWaitForSingleObject function to wait for the event to be set to the signaled state before calling PostThreadMessage. In the thread to which the message will be posted, call PeekMessage(&amp;msg, NULL, WM_USER, WM_USER, PM_NOREMOVE) to force the system to create the message queue. Set the event, to indicate that the thread is ready to receive posted messages. 
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:maorachow 回复日期:2003-05-09 09:18:06
<br>内容:Good!
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -