Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!microsoft!kensy From: kensy@microsoft.UUCP (Ken SYKES) Newsgroups: comp.windows.ms Subject: Re: How are multiple Windows applications scheduled? Message-ID: <57124@microsoft.UUCP> Date: 2 Sep 90 20:03:26 GMT References: <920@digi.lonestar.org> Reply-To: kensy@microsoft.UUCP (Ken SYKES) Organization: Microsoft Corp., Redmond WA Lines: 59 In article <920@digi.lonestar.org> cwinemil@digi.lonestar.org (Chris Winemiller) writes: >How does Windows 3.0 achieve the "simultaneous" execution of multiple >Windows applications? (Note: I am excluding "simultaneous" execution of >multiple DOS sessions in the 386 enhanced mode.) Must the Windows >applications be written in such a way as to voluntarily "relinquish" >control of the CPU occasionally? Or are the Windows applications >written as if each is the only one running on the CPU? In other words, >does Windows do non-preemptive "scheduling" or preemptive "scheduling"? >Chris Winemiller INTERNET: cwinemil@digi.lonestar.org >DSC Communications Corporation UUCP: ...uunet!digi!cwinemil Windows programs are scheduled non-preemptively. It is based on a message passing system: each program has a message loop similar to the following: WinMain() { Create windows, initialize, etc. while (GetMessage( stuff )) { TranslateMessage( stuff ); DispatchMessage( stuff ); } return exit code; } The primary point that Windows switches between applications is at the GetMessage call. Before returning the next event to the application it can go off and execute some other program for awhile. Eventually the application that called GetMessage will be started up again and given the next event in its queue. This is the essence of multitasking in windows. You can also explicitely relinquish control by calling Yield or you can modify the message loop to do things during idle time: for (;;) /* loop forever */ { /* process any pending events */ while (PeekMessage( stuff )) { if (message == "quit") break; TranslateMessage( stuff ); DispatchMessage( stuff ); } /* system is idle. do something useful here */ } Windows apps can also be hooked into external events such as key presses or timer events. This is intended to give you a taste of how Windows multitasks. If you have any specific questions please post them to the net. Ken Sykes Disclaimer: The above opinions are solely my own.