Operating systems -- using minimum number of semaphores
Posted
by
stackuser
on Programmers
See other posts from Programmers
or by stackuser
Published on 2013-10-27T23:18:44Z
Indexed on
2013/10/28
4:03 UTC
Read the original article
Hit count: 378
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)
© Programmers or respective owner