Kaps
April 8th, 1999, 06:31 AM
Hi All,
I am facing a problem in multithreading. As I am creating 2 threads and wants one thread to Post messages by PostThreadMessage()and the other thread receive the messages be PeekMessage().
At first in the receiving thread I am forcing to create the message queue by this call.
PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
and then putting the thread in a while loop to receive the messages by
while(1)
{
ret = PeekMessage (&msg, NULL, MSG1, MSG2, PM_NOREMOVE);
if(ret == 1)
{
// Gets the Message
}
--
--
}
Now while posting the message in the sending thread , I am using
ret = ::PostThreadMessage(ThreadID,MSG1,NULL, NULL);
ret = ::PostThreadMessage(ThreadID,MSG2,NULL, NULL);
so both 'ret' are returning 1 , i.e posting the message is succes.
and at the receiving thread I am only able to get the the first message( MSG1) not the second ( MSG2).
But if I uses WaitforSingleObject(event, INFINITE)between these 2 PostMessage commands then I am able receive both the messages at the receiving thread !!
Can you pls tell me why this is happening !!!
regards,
Kapil
I am facing a problem in multithreading. As I am creating 2 threads and wants one thread to Post messages by PostThreadMessage()and the other thread receive the messages be PeekMessage().
At first in the receiving thread I am forcing to create the message queue by this call.
PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
and then putting the thread in a while loop to receive the messages by
while(1)
{
ret = PeekMessage (&msg, NULL, MSG1, MSG2, PM_NOREMOVE);
if(ret == 1)
{
// Gets the Message
}
--
--
}
Now while posting the message in the sending thread , I am using
ret = ::PostThreadMessage(ThreadID,MSG1,NULL, NULL);
ret = ::PostThreadMessage(ThreadID,MSG2,NULL, NULL);
so both 'ret' are returning 1 , i.e posting the message is succes.
and at the receiving thread I am only able to get the the first message( MSG1) not the second ( MSG2).
But if I uses WaitforSingleObject(event, INFINITE)between these 2 PostMessage commands then I am able receive both the messages at the receiving thread !!
Can you pls tell me why this is happening !!!
regards,
Kapil