ImageVerifierCode 换一换
格式:DOCX , 页数:18 ,大小:194.88KB ,
资源ID:7760660      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bingdoc.com/d-7760660.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(静态优先级调度算法Word格式文档下载.docx)为本站会员(b****3)主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(发送邮件至service@bingdoc.com或直接QQ联系客服),我们立即给予删除!

静态优先级调度算法Word格式文档下载.docx

1、由自己设计。三、实验原理及步骤 根据现代操作系统的特征1并发性(concurrence);2共享性(sharing);3虚拟性(virtual);4异步性(asynchronism) 。模拟出进程在执行中的状态变化过程;体会进程申请资源、使用资源、归还资源;体会死锁。步骤(参考框图)4、 算法和流程图可强占优先调度算法实现过程流程图(如下图): 四、程序运行1 选择输入执行程序(如下图) 2 可强占优先调度算法图(如下图)五.设计总结:通过该课程设计,加深了对系统进程调度机制的理解。在抢占方式中实践了“抢占” 必须遵循的原则:优先权原则。认识了几种进程调度算法的优缺点以及应用范围。加强C+的编

2、程能力,实现类的封装。附录:程序及注释(用红色黑体标注自己设计的函数)/进程PCB类和模拟cpu的进程类的声明#include stdlib.hwindows.hconio.htime.hio.hstring.h#define MAX_PHILOSOPHERS 3 /待测试的哲学家数#define ZERO 48 /数字0的ASCII码#define DELAY rand()%25struct PCB char p_name20; int p_priority; int p_needTime; int p_runTime; char p_state; char deadlock(); stru

3、ct PCB* next;void HighPriority();void deadlock();void Information();/形参的改变映射给实参 说白了就是实参传过去不用return 返回就可以把实参改变char Choice();struct PCB* SortList(PCB* HL);int main(int argc,char *argv) Information(); char choice = Choice(); switch(choice) case 1: system(cls); HighPriority(); break;2 void deadlock(); d

4、efault: pause return 0;void Information() printf(nn * n 模拟进程调度算法n * nnn 静态优先级调度算法 死锁问题 按回车键进入演示程序 getchar();char Choice() 进程调度演示n 1.演示最高优先数优先算法。n 2.演示死锁问题。 3.退出程序。nnnn 选择进程调度方法:select a function(13): char ch = getchar(); return ch;void HighPriority() struct PCB *processes, *pt; /pt作为临时节点来创建链表 proces

5、ses = pt = (struct PCB*)malloc(sizeof(struct PCB); for (int i = 1; i != 4; +i) struct PCB *p = (struct PCB*)malloc(sizeof(struct PCB);进程号No.%d:, i);输入进程名: scanf(%s, p-p_name);输入进程优先数:%d, &p-p_priority);输入进程运行时间:p_needTime); p-p_runTime = 0;p_state = W;next = NULL; pt-next = p; pt = p; /接受回车 /process

6、es作为头结点来存储链表 processes = processes-next; int cases = 0; struct PCB *psorted = processes; while (1) +cases; pt = processes; /对链表按照优先数排序 /psorted用来存放排序后的链表 psorted = SortList(psorted);The execute number: %dnn, cases);* 当前正在运行的进程是:%sn, psorted- psorted-Rqname state super ndtime runtimen%st%ct%dt%dt%dtn

7、np_name, psorted-p_state, psorted-p_priority, psorted-p_needTime, psorted-p_runTime);p_runTime+;p_priority-;* 当前就绪状态的队列为: /pt指向已经排序的队列 pt = psorted- while (pt != NULL), pt-p_name, pt-p_state, pt-p_priority, pt-p_needTime, pt- pt = pt- /pt指向已经排序的链表,判断链表是否有已用时间啊等于需要时间的 pt = psorted; struct PCB *ap; ap

8、 = NULL; /ap指向pt的前一个节点 if (pt-p_needTime = pt-p_runTime) if (ap = NULL) psorted = pt; else ap-next = pt- ap = pt; if (psorted-next = NULL)struct PCB* SortList(PCB* HL) struct PCB* SL; SL = (struct PCB*)malloc(sizeof(struct PCB); SL = NULL; struct PCB* r = HL; while (r ! struct PCB* t = r- struct PCB

9、* cp = SL; struct PCB* ap = NULL; while (cp ! if (r-p_priority cp-p_priority) ap = cp; cp = cp- r-next = SL; SL = r;next = cp;next = r; r = t; return SL;/HANDLE h_mutex_chopsticksMAX_PHILOSOPHERS; /互斥体数组,每根筷子需要一个互斥体int thread_numberMAX_PHILOSOPHERS=1,2,3;/定义死锁的个数/会产生死锁的哲学家线程int deadlock_philosopher(

10、LPVOID data) int philosopher_number=*(int *)(data); /哲学家编号 for(;) srand( (unsigned)time( NULL ) * ( philosopher_number+ 1) ); Sleep(DELAY); printf(%s%c%s%cn,Philosopher ,ZERO+philosopher_number, is waiting chopstick ,(ZERO+philosopher_number); WaitForSingleObject(h_mutex_chopsticksphilosopher_number

11、, INFINITE); got chopstick Sleep(DELAY/4); printf(,(ZERO+(1+philosopher_number)%MAX_PHILOSOPHERS); WaitForSingleObject(h_mutex_chopsticks(1+philosopher_number)%MAX_PHILOSOPHERS), INFINITE);%s%c%sn is eating. ReleaseMutex(h_mutex_chopsticksphilosopher_number); released chopstick ,ZERO+philosopher_num

12、ber); ReleaseMutex(h_mutex_chopsticks(1+philosopher_number)%MAX_PHILOSOPHERS); Sleep(DELAY); / end for/死锁时的初始化程序void deadlock() char choice; int i=0; HANDLE h_threadMAX_PHILOSOPHERS;可能出现死锁的哲学家就餐问题n for(i=0;iMAX_PHILOSOPHERS;i+) h_mutex_chopsticksi=CreateMutex(NULL,FALSE,NULL); ; h_threadi=CreateThre

13、ad(NULL,0,(LPTHREAD_START_ROUTINE)(deadlock_philosopher),&thread_numberi,0,NULL); WaitForMultipleObjects(MAX_PHILOSOPHERS,h_thread,TRUE,-1); do choice=(char)getch(); while( choice!= deadlock();nPress any key to return to main menu. getch();/通过按序分配资源预防死锁的哲学家线程int ordered_allocation_philosopher(LPVOID

14、 data) if(philosopher_number=MAX_PHILOSOPHERS-1) printf( WaitForSingleObject(h_mutex_chopsticks(1+philosopher_number)%MAX_PHILOSOPHERS, INFINITE); Sleep(DELAY/4); else,ZERO+(1+philosopher_number)%MAX_PHILOSOPHERS); is releasing chopstick /通过按序分配资源预防死锁的初始化程序void ordered_allocation()i+) h_threadi=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)(ordered_allocation_philosopher),&

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2