西北工业大学 操作系统实验 实验报告
一、实验目的
掌握 GeekOS 系统的线程调度算法以及线程同步与互斥方法,实现线程调度
的优化与控制。
二、实验要求
1. 按照实验讲义 P146 页中的设计要求,增加线程调度算法的选择策略,使
系统可以在时间片轮转调度和四级反馈队列调度之间切换,并且实现四级反馈队
列调度算法,给出关键函数的代码以及实验结果。
2. 在 GeekOS 中实现信号量,使用信号量保证用户程序运行时的线程同步,
给出关键函数的代码以及实验结果。
三、实验过程及结果
答:
1、进程间的调度实现:
Get_Next_Runnable 代码如下:
struct Kernel_Thread* Get_Next_Runnable(void)
{
struct Kernel_Thread* best = 0;
int i, best_index_queue = -1;
if (g_schedulingPolicy == ROUND_ROBIN) {
struct Kernel_Thread* best_in_queue = NULL;
for (i = 0; i < MAX_QUEUE_LEVEL; i++){
best_in_queue = Find_Best(&s_runQueue[i]);
if (best == NULL) {
best = best_in_queue;
best_index_queue = i;
} else if (best_in_queue != NULL){
if (best_in_queue->priority > best->priority) {
best = best_in_queue;
best_index_queue = i;
}
}