欢迎光临散文网 会员登陆 & 注册

操作系统之信号量代码填空题!!!

2021-07-02 20:35 作者:阿逸家的猫猫  | 我要投稿

原子操作:

P:

down(s) {

S--; 

if (s>0) {  

place this process in s.queue;  

block this process;

}

}

V:

up(s) {

s++;

if (s<=0) {  

remove a process from s.queue;  

place the process on ready list; 

}

}


课本基础:

1.独木桥问题(west------bridge------east)

严格轮流,西先行:

Semaphore S1=1,S2=0;

Void WTE (void) {

while(TRUE)      {

down(&s1);

pass(    );  

up(&s2);

}

}


Void ETW (void){

while(TRUE)  {    

down(&s2); 

pass(    );

up(&s1);

     }

}

2.生产者、消费者问题(The producer-consumer problem )

注意down操作同步信号量写在互斥信号量前,up操作都可以

3.读者、写者问题(The readers and writers problem)

读写者对rc访问互斥,mutex保护rc


课外考点:



操作系统之信号量代码填空题!!!的评论 (共 条)

分享到微博请遵守国家法律