1、. . . . .指导教师评阅成绩:XXX1: 实验项目一项目名称:实验目的:实验时间:人员分工:实验环境:实验环境的搭建过程、选用的操作系统、机器配置、编译器等。实验内容:对实践过程的详细说明,针对已经满足的实践要求,采用了何种算法或思想,对Nachos平台的哪些代码进行了什么样的修改。实验结果:对实践要求的满足程度,代码是否编写完成,是否调试通过,能否正常运行,本项目的要求中共满足了哪几项。参考文献:实验项目二实验项目名称:Nachos中的线程管理实验项目目的:1.最多能够同时存在128个用户线程 2.改变为遵循“优先级调度”的抢占式调度 参与人员及分工:乔心轲,何赵平,康小芳完成主要代码
2、编写;崔蓉,张文进行程序的测试及维护。n Nachos: Not Another Completely Heuristic Operating Systemn Linuxn Gcc n Windows1.对于最多能够同时存在128个用户线程,我们在Thread.cc中声明了一个static变量numOfThreads;具体代码如下:static int numOfThreads = 0;/the count of the threads在Thread的构造函数中对其值进行加1;即每创建一个线程时,都会把numOfThreads加1;+numOfThreads; 并在SimpleThread()
3、中进行了如下修改,完成了最多能够同时存在128个用户线程。static voidSimpleThread(int which) if(numOfThreads128) for(inti=0;icurrentThread-Time()-(kernel-executeTime)+2;i+) cout * thread whichexecuteTime times.n;coutpriority Priority()Yield(); elseif(count = 0) printf(The number of the threads can not be larger than 128!);kerne
4、l- count+; 为了实现遵循“优先级调度”的抢占式调度策略,首先为Thread增加了三个变量:executeTime;time;priority在Thread.h中对它们的声明:public: Thread(char* debugName);/ initialize a Thread Thread(); / deallocate a Thread/ NOTE - thread being deleted/ must not be running when delete / is called int executeTime;/The time that this thread has e
5、xecuted / basic thread operation void setExTime(int exT);/set the executeTime of the thread to exT int Time();/return the time that the thread should be served void setTime(int t);/set the time that the thread should be served to t void setPriority(int pri); /set the priority of the thread to priint
6、 Priority(); /return the priority of the thread private: / some of the private data for this class is listed above int time; / the time that the thread should be served int priority; /the priority of each thread在Thread.cc中的实现:Thread:Thread(char* threadName) name = threadName; stackTop = NULL; stack
7、= NULL; status = JUST_CREATED; for (int i = 0; i interrupt;Scheduler *scheduler = kernel-scheduler;IntStatus oldLevel;DEBUG(dbgThread, Forking thread: name f(a): (int) func SetLevel(IntOff); scheduler-ReadyToRun(this);/ ReadyToRun assumes that interrupts / are disabled! (void) interrupt-SetLevel(old
8、Level); +numOfThreads; /-/Thread:setExTime/ set the executeTime of the thread to exTvoidsetExTime(int exT) executeTime = exT;setPriority/ set the priority of the thread to prisetPriority(int pri) priority=pri;Priority/ return the priority of the threadintPriority() return priority;/ set the time of the thread to t
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1