急急急————-高分(80以上)求救于计算机英语高手.
The 16-bit versions of Windows did not arbitrarily switch control from one Windows program to another based on a timer tick. Instead, any task switching took place when a program had finished processing a message and had returned control to Windows. This nonpreemptive multitasking is also called "cooperative multitasking" because it requires some cooperation on the part of applications. One Windows program could tie up the whole system if it took a long time processing a message.
Although nonpreemptive multitasking was the general rule in 16-bit Windows, some forms of preemptive multitasking were also present. Windows used preemptive multitasking for running DOS programs and also allowed dynamic-link libraries to receive hardware timer interrupts for multimedia purposes.
The 16-bit Windows included several features to help programmers solve—or at least cope with—the limitations of nonpreemptive multitasking. The most notorious is, of course, the hourglass mouse cursor. This is not a solution, of course, but just a way of letting the user know that a program is busy working on a lengthy job and the system will be otherwise unusable for a little awhile. Another partial solution is the Windows timer, which allows a program to receive a message and do some work at periodic intervals. The timer is often used for clock applications and animation.
Another solution to the limitations of preemptive multitasking is the PeekMessage function call, as we saw in Chapter 5 in the RANDRECT program. Normally, a program uses the GetMessage call to retrieve the next message from its message queue. However, if there are no messages in the message queue, then GetMessage will not return until a message is present. PeekMessage, on the other hand, returns control to the program even if no messages are pending. Thus, a program can perform a long job and intermix PeekMessage calls in the code. The long job will continue running as long as there are no pending messages for the program or any other program.
PM and the Serialized Message Queue
The first attempt by Microsoft (in collaboration with IBM) to implement mulittasking in a quasi-DOS/Windows environment was OS/2 and the Presentation Manager (PM). Although OS/2 certainly supported preemptive multitasking, it often didn't seem as if this preemption was carried over into the Presentation Manager. The problem is that PM serialized user input messages from the keyboard and mouse. What this means is that PM would not deliver a keyboard or mouse message to a program until the previous user input message had been fully processed.
Although keyboard and mouse messages are just a few of the many messages a PM (or Windows) program can receive, most of the other messages are the result of a keyboard or mouse event. For example, a menu command message is the result of the user making a menu selection using the keyboard or mouse. The keyboard or mouse message is not fully processed until the menu command message is processed.
The primary reason for the serialized message queue was to allow predictable "type-ahead" and "mouse-ahead" actions by the user. If one of the keyboard or mouse messages caused a shift in input focus from one window to another, subsequent keyboard messages should go to the window with the new input focus. So, the system doesn't know where to send a subsequent user input message until the previous ones have been processed.
窗口的 16 个一点点的版本没有任意地来自窗口的开关控制对另外一规划基於一个定时器勾号。 改为,当一个计画已经 处理一个信息完并且已经 退还对窗口的控制时候 , 任何的工作转变发生。 因为它需要申请的部份上的一些合作 , 所以 nonpreemptive 多工化也被称为 "合作的多工化" 。 是否它花了长的时间处理一个信息,一个窗口计画可以绑好整个的系统。
虽然 nonpreemptive 多工化在 16 个一点点的窗口中是一般的规则,但是一些形式 的先买多工化也是礼物。 窗口用了先买的为流动的操作系统计画多工化以及允许了电动的- 联编图书馆为多媒体目的接受硬件定时器中断。
16 个一点点的窗口包括了一些特征帮助程序师解决—否则至少控制 — nonpreemptive 多工化的限制。 最声名狼藉的当然是时漏老鼠光标。 这不是解决, 当然,但是只是让使用者的一个~的方式知道一个计画是忙碌的处理 一种冗长的工作,而且系统将会是否则无法使用的对一会儿稍微。 另外的部分解决是窗口定时器, 允许一个计画在周期的间隔接受一个信息而且做一些工作。 定时器时常作为 时钟申请和动画。
另外的对~解决办法先买的多工化的限制是 PeekMessage 功能呼叫,如同我们在 RANDRECT 计画中的第 5 章中看见一样。 正常地,一个计画使用 GetMessage 呼叫取回来自它的信息储列的下个信息。然而 ,如果在信息储列中没有信息,那麽 GetMessage 直到一个信息在场将不归还。 PeekMessage, 另一方面,回返控制到计画即使没有信息是当的时候。 因此,一个计画能在密码中运行一种长的工作而且混入 PeekMessage 呼叫。 长的工作将会继续跑只要在那里当信息的时候为计画或任何其他的计画没有。
PM 和被写成连载长篇而刊登的信息储列
在一个类似的-操作系统/ 窗口环境中实现 mulittasking 的微软 (在有 IBM 的合作方面) 的第一尝试是操作系统/2 和发表经理.(PM) 虽然操作系统/2 确定地支援了先买的多工化,它时常不 像是好像这个先买结束进入发表经理之内是被运的。 问题是 PM 写成连载长篇而刊登了来自键盘和老鼠的使用者输入信息。 这所意谓的是 PM 不运送键盘或老鼠信息给一个计画直到早先的使用者输入信息已经 完全被处理。
虽然键盘和老鼠信息只是少数的许多信息一个 PM( 或窗口) 计画能接受,大多数的另一个信息是键盘或老鼠事件的结果。 举例来说, 一个菜单指令信息使用者制造一个菜单选择的结果正在使用键盘或老鼠吗。 键盘或老鼠信息是不完全处理直到菜单信息被处理的指令。
主要的理由为被写成连载长篇而刊登的信息储列要允许使用者的可预期的 "类型 - 向前地" 和 "老鼠 - 向前地" 行动。如果键盘之一或老鼠信息从一扇窗户到另外一引起输入焦点的变化,后来的键盘信息应该用 新的输入焦点去窗户。如此,系统不 知道该哪里送一个后来的使用者输入信息直到早先的一些有被处理。
基于时间片的16位windows操作系统不能从一个windows应用程序向另外一个windows应用程序arbitrarily切换控制权。相反,任何一种
任务的切换发生在一个程序完成了消息的处理并且返回控制权给操作系统。这种nonpreemptive多任务也被称为"协同式多任务",这是因为它需
要各个应用程序之间的协同工作。如果一个windows程序用一段很长的时间来处理消息,那么,它就绑定到整个操作系统,阻塞其它进程的执行
。
尽管nonpreemptive多任务作为一般规则存在于16为操作系统中,一些preemptive多任务的形式仍然存在。windows的preemptive多任务方
式被用来运行dos程序,也可以让动态连接库接受硬件时钟中断来处理多媒体请求。
16位的windows操作系统拥有几个特征,这些特征有助于程序员解决-或至少弥补-nonpreemptive多任务的不足。最notorious(重要)的当然
是,沙漏鼠标指针。显然,这不是一个解决的办法,但是,它却能告诉用户程序正在忙于处理一个大任务,并且,系统被挂起一小段时间。另
外一种解决办法则是利用系统时钟,它可以让一个程序在中断期间接受到一个消息并处理相应工作。时钟控件经常被用在和时钟相关的程序和
动画程序中。
解决preemptive多任务的另外一个办法是peekmessage函数调用,我们在第五章中看到的"RANDRECT"程序就是利用了同样的方式。通常,一
个程序使用GetMessage调用从消息队列中检索下一个消息。然而,如果消息队列为空,GetMessage函数将不会有任何返回直到有消息存在于消
息队列中。另外一个方面,PeekMessage移交控制权给程序,即使没有消息正在pending。就这样,一个程序便能够执行一个大的工作并在在代
码中间隔交替的执行PeekMessage调用。大任务能够继续运行直到没有任何对于本程序或其它程序的分发消息。
PM(Presentation Manager)和序列化消息队列
在quasi-DOS/Windews环境中,由微软测试执行多任务的第一次尝试是OS/2和代理管理。尽管os/2一定支持preemptive多任务,但是,它看
起来好像这个preemption被PM承载运行。问题是PM序列化从键盘和鼠标得到的用户输入消息。这意味着PM不能够分发键盘或鼠标消息
到程序,直到先前用户的输入消息已经被完全处理了。
尽管键盘和鼠标消息仅仅是PM(或者WINDOWS)程序能够接受到的一小部分消息,但是,大多数其它消息也是由键盘和鼠标事件触发的。举个
例子,一个菜单消息就是用户是用鼠标或键盘选择菜单的结果。随后的键盘或鼠标消息不能够完全被处理直到菜单命令消息被处理了。
序列化消息队列的主要原因是队列容许由用户发出的可预测的"类型前导"和"鼠标前导"操作。如果键盘或鼠标的一个消息在从一个窗体到另外一个窗体的输入焦点中引发了一个加操作,那么,键盘的子序列消息应该转移到窗体的新输入焦点中。因此,系统便不知道将用户输入的子序列消息发送到何处,直到先前一个用户已经将产生的消息处理完了。