News:

Build a stunning handcrafted website with IT Acumens

Main Menu

Multi Tasking in VC++

Started by karthikn, Jul 18, 2008, 08:05 PM

Previous topic - Next topic

karthikn

Cooperative Multitasking: Yielding in the Message Loop

As I mentioned earlier, authors of most simple Windows applications do not have to worry about cooperative multitasking. The typical message loop, shown in Listing 12.1, takes care of this problem. Every time the application becomes ready to process a new message, it calls the Windows GetMessage function. GetMessage, in turn, may not return immediately; instead, Windows may perform a context switch and pass control to another application.

Yielding in the message loop.

int WINAPI WinMain(...)

{

    MSG msg;

    ...

    // Application initialization goes here

    ...

    // Entering main message loop

    while (GetMessage(&msg, NULL, 0, 0))    // This call yields!

    {

        // Message dispatching goes here

        ...

    }

}