8

I have read that Windows 3.11 uses cooperative multitasking, which means that the OS does not do process scheduling whenever it wants, but rather the currently running process "yield" the execution to the OS whenever the process wants, and then the OS chooses the next process to run.

But what I want to know is what is this "yield" functionality, is it a Windows API function that a process must call in multiple places in the process's code?

rony_t
  • 201
  • 1
  • 3
  • 1
    https://youngmumpster.wordpress.com/2013/10/13/windows-multitasking-a-historical-aside/ – Thomas Junk Jun 12 '17 at 15:20
  • Possible duplicate of [How does the operating system regain control when multitasking?](https://softwareengineering.stackexchange.com/questions/200861/how-does-the-operating-system-regain-control-when-multitasking) – gnat Jun 12 '17 at 15:20
  • 2
    @gnat while one of the answers there addresses cooperative multitasking in general, I don't think this is a duplicate of that question. And it was closed as a duplicate itself (of the more general https://softwareengineering.stackexchange.com/q/82432/187318). None of these address how the mechanism used to be implemented in a specific OS, as far as I can see. – Hulk Jun 12 '17 at 15:29
  • 1
    @gnat: where in that other question do you see anything specific for **Windows (3.11)**? – Doc Brown Jun 12 '17 at 16:18

2 Answers2

16

It was done in the GetMessage call.

The heart of a windows application is something like:

while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
    TranslateMessage(&Msg);
    DispatchMessage(&Msg);
}

Each iteration gets a message and dispatches it. If there isn't a message available, it blocks until a message is available. Under 16-bit Windows, the CPU was yielded while waiting for a new message.

Some other calls like Yield or SendMessage would work the same way. But GetMessage was the one that most GUI applications would have primarily used.

Source

user3840170
  • 215
  • 1
  • 9
Winston Ewert
  • 24,732
  • 12
  • 72
  • 103
  • 2
    Right. I vaguely recall long ago tracing through a GetMessage call (in SoftICE) until it returned into another application. That's the way I remember win16 cooperative multitasking. When you call GetMessage() windows might return to some other app, process their message, then later return to you after some other app makes a yielding call. GetMessage() was not the only yielding call. GetMessage() made your app and other apps coroutines of each other. – joshp Jun 12 '17 at 17:31
2

Aside from the explicit request to Yield(), there are other APIs provided by Windows which potentially have to wait for another process to provide an answer, like the heart of the message pump GetMessage(), asking a window for information with SendMessage() and many more.

Deduplicator
  • 8,591
  • 5
  • 31
  • 50