Operating systems theory -- using minimum number of semaphores
Posted
by
stackuser
on Programmers
See other posts from Programmers
or by stackuser
Published on 2013-10-29T08:06:11Z
Indexed on
2013/10/29
10:17 UTC
Read the original article
Hit count: 542
This situation is prone to deadlock of processes in an operating system and I'd like to solve it with the minimum of semaphores. Basically there are three cooperating processes that 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. Semaphores should be used to synchronize:
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
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'm sure that any kernel programmers that happen on this can knock this out in a minute or 2.
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