Special case scheduling [closed]

天涯浪子 提交于 2019-12-01 09:41:38

问题


So here's the question. While studying about process scheduling I came across two seemingly contradictory examples I just can't get my head around.

The problem arises if for instance in the priority non-preemptive scheduling algorithm which always chooses the process with the highest priority to be run next and once running, process can only volontarily give up its CPU time, that is no other process can run until the currently running process finishes. It seems that what the solution the book proposes is that if both end of one process and arrival of the new high-priority process occur at the same time, the new high-priority process will be added to the ready queue and then chosen by the scheduler to be run next.

But in the other example in Round-robin algorithm, if there is only one process in the ready queue and it is currently running, if at the same time its quantum elapses and new process says its ready, it seems that the proposed solution is that the scheduling will be done first, so the currently running process will continue to run while the new process will be added to the queue.

I'd be grateful if someone clarified this to me, because I know from some other post that context switch does not occur in round robin for single process in queue, but is it true in general that scheduling is done before adding new process to queue.


回答1:


What I get from you description is:

Time 0:

Process 1 starts using its time slice, e.g. 5 units.

Time 5:

Process 2 arrives. Process 1 used up its time slice and is replenished.

A round robin scheduler checks the ready queue by selecting the next process with time left. At time 0 your ready queue looks like this:

P1

At time 5:

P1 going over to P1 -> P2

Tanenbaum writes in Modern Operating Systems: When a process used up it's time slice, it is enqueued at the end. So what happens is, that P1 is enqueued again before P2 is enqueued for the first time. This saves an additional context switch from P1 to P2 and back to P1. If you want P2 to be run first, then you can use priority base round robin.



来源:https://stackoverflow.com/questions/20360925/special-case-scheduling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!