题海让大学四年没有难题
白天模式登陆

题目详情

单选题 有(P1,P2,P3,...,Pn)n个进程每次将1字符读入到一个容量为80的缓冲区中,当缓冲区满后,有另一个进程Pb负责一次取走这80个字符.请选择合适的选项完善下述代码,实现各进程的正确操作. int mutex=1; //互斥信号量,用于互斥访问共享变量count int empty=80; //同步信号量,表示当前缓冲区可容纳的字符个数 int full=0; //同步信号量,1表示缓冲区满,0表示缓冲区未满 int count=0; //计数变量 process Pi( ) // i=1, 2, 3, ... , n { while (1) { 读入一个字符; ① ; P(mutex); 将读入的字符存入缓冲区; count++; if (count==80) ② ; V(mutex);} } process Pb( ) { while (1) { ③ ; P(mutex); 从缓冲区取走80个字符; count=0; V(mutex); for ( i=0; i<80; i++) ④ ;} }

A. ①P(full) ②V(full) ③P(empty) ④V(empty)

B. ①V(empty) ②P(full) ③V(full) ④P(empty)

C. ①V(full) ②P(empty) ③V(empty) ④P(full)

D. ①P(empty) ②V(full) ③P(full) ④V(empty)

操作系统-2024课程封面

学科:操作系统-2024

时间:2024-04-11 02:31:20

Copyright © 2022 津ICP备2021001502号