资源分配算法(Resource allocation algorithm)
# includes string.h > <
# includes ctype.h > <
# includes < malloc.h > / * malloc () 等 * /
# includes < limits.h > / * int _ max等 * /
# includes < stdio.h > / * eofl (= ^ z或f6), null * / # includes < stdlib.h > / * atoi () * /
# includes < io.h > / * - eof () * /
# includes math.h > / < * floor (), ceil (), abs () * / # includes < process.h > / * exit () * /
# includes iostream > <
using namespace std;
# includes time.h > <
# define buf 10 / / 缓存的大小
# define max 20 / / 最大可以输入的字符
/ / 数据结构的定义和全局变量
typedef struct pcb {
char name [10]; / / 进程名
char were [10]; / / 运行状态
char reason [10]; / / 若阻塞, 其原因int breakp; / / 断点保护
struct pcb * next; / / 阻塞时的顺序} * link; pcb
int s1, s2; / / 信号量
link p1; / / 生产者进程
生吃芹菜link c1; / / 消费者进程
普世价值char str [max]; / / 输入的字符串char buffer [buf]; / / 缓冲池
qq邮箱怎么注销
int len); / / 输入长度
int sp = 0; / / string的指针
int = 0; / / 生产者指针
int out = 0; / / 消费者指针
char temp; / / 供打印的临时产品char chr _ p [max]; / / 生产记录int rp1 = 0; / / 生产记录指针char chr _ c [max]; / / 消费记录int rp2 = 0; / / 消费记录指针link ready; / / 就绪队列
link b _ s1; / / s1阻塞队列
link b _ s2; / / s2阻塞队列
int bw; / / 程序计数器
int count; / / 字符计数器
int with _ cnt; / / 消费计数器void init (); / / 初始化
void f (int); / / p操作
void v (int s); / / v操作
void block (int s); / / 阻塞函数
田园风光图片
void wakeup (int s); / / 唤醒函数
void control (); / / 处理机调度弯曲的箭头
void processor (); / / 处理机执行
void print (); / / 打印函数
void init () {/ / 初始化
过去与未来s1 = buf;
s2 = 0;
p1 = (link) malloc (sizeof (pcb)); / / 建立新的结点, 并初始化为生产者
strcpy (p1 - > name, "producer");
strcpy (p1 - >, "ready").
strcpy (p1 - > reason, "null");
p1 - > breakp = 0;
p1 - > next = null;
c1 = (link) malloc (sizeof (pcb)); / / 建立新的结点, 并初始化为消费者
strcpy (c1 - > name, "consumer");
strcpy (c1 - >, "ready").
故事会官网strcpy (c1 - > reason, "null");
c1 - > breakp = 0;
c1 - > next = null;
ready = p1.
ready - > next = 1; / / 初始化为生产进程在前, 消费进程在后c1 - > next = null;
烫菜b _ s1 = null;
b _ s2 = null; / / 阻塞进程为null
pc = 0;
with _ cnt = 0; / / 消费计数器
}
void f (int) {
if (n = = 1) {/ / p (s1)
s1 - -;