Operating systems -- using minimum number of semaphores
- by stackuser
The three cooperating processes all read data from the same input device. Each process, when it gets the input device, must read two consecutive data. I want to use mutual exclusion to do this. The declaration and initialization that I think would work here are:
semaphore s=1
sa1 = 0, sa2 = 0, sb1 = 0, sb2 = 0, sc1 = 0, sc2 = 0
I'd like to use semaphores to synchronize the following processes:
P1: P2: P3:
input(a1,a2) input (b1,b2) input(c1,c2)
Y=a1+c1 W=b2+c2 Z=a2+b1
Print (X) X=Z-Y+W
I'm wondering how to use the minimum number of semaphores to solve this.
Diagram of cooperating Processes and one input device:
It seems like P1 and P2 would start something like:
wait(s)
input (a1/b1, a2/b2)
signal(s)