buf 1 buf 2 mutex 1 mutex 2

  • Slides: 15
Download presentation

输入进程 → buf 1 → 计算进程 → buf 2 → 打印进程 对键盘输入进程而言, 计算进程是消费者进程; 而对打印输出进程而言,

输入进程 → buf 1 → 计算进程 → buf 2 → 打印进程 对键盘输入进程而言, 计算进程是消费者进程; 而对打印输出进程而言, 计算进程又是生产者进程 mutex 1, mutex 2, empty 1, empty 2, full 1, full 2: =1, 1, 0, 0; 输入进程 while(true){ P(empty 1); P(mutex 1); input a charcter from keyboard; Add to buffer; V(mutex 1); V(full 1); } 计算进程 while(true){ P(full 1); P(mutex 1); Take a charactor from buffer 1; Add to ch 1; V(mutex 1); V(empty 1); P(empty 2); P(mutex 2); Take a charactor from ch 1; Add to buffer 2; V(mutex 2); V(full 2); } 打印进程 while(true){ P(full 2); P(mutex 2); Take a charactor from buffer 2; Add to printer controler; start printer; V(mutex 2); V(empty 2); }