In the Message Loop of a windows application,the GetMessage() function will suspend the application thread when there is no message in the message queue, but how it manages to wake itself up when a message was enqueued into the message queue? How can a sleeping thread wake itself up?
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
They wait in the same manner as how a typical asynchronous wait thread waits (using
WaitForSingleObject). Internally (in the kernel level), they all wait using a kernel API function calledKeWaitForSingleObject