0

was hoping someone could help me with semaphores...im a little confused

heres the question:

There are three kinds of processes in a system: type A, type B and type C. There are
many processes of types A and B, but only one process of type C. The type C process
cannot begin its task (Task_C()) until n processes of type A or m processes of type B
finish their respective tasks. More specifically, the type C process must block itself until
enough processes of type A or type B complete their tasks. Write synchronization code
for the three types of processes using semaphores. Use the templates below for each
process type. Hint: You’ll also want to use integer counts.

3
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by jaux
0
a = b = 0 # shared counters
sem(0)    # semaphore initialized to 0

func_A:   # code for type A process
    a = a + 1
    sem.V

func_B:   # code for type B process
    b = b + 1
    sem.V

func_C:   # code for type C process
    while (a < n && b < m):
        sem.P
    # critical section
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.