1. A producer P and consumer C communicate by means of three semaphores and a buffer that has a capacity of 10. Semaphore M enforces mutual exclusion; it is intially 1, is decremented by whichever process wants to enter its critical region (the code that adds or removes items from the buffer), and incremented back to 1 after leaving the critical region. Semaphore F counts the number of full slots in the buffer. It is initially 0, is decremented by C before entering its critical region, and incremented by P after leaving its critical region. Semaphore E counts the number of empty slots in the buffer. It is initially 10, is decremented by P before entering its critical region, and incremented by C after leaving its critical region. Before entering a critical region, a process first tries to decrement E or F, and then tries to decrement M. On leaving a critical region, a process first raises M and then E or F. Under these assumptions, what are the possible combinations of values of E, F, and M that can exist? Identify, in the list below, the combination that cannot exist. a) M=0, E=7, F=1 b) M=1, E=8, F=2 c) M=1, E=5, F=2 d) M=1, E=6, F=3 2. A producer P and a consumer C have a buffer of capacity 2 between them. The following sequence of actions occurs: Step Actor Item 1 P 1 2 P 2 3 P 3 4 C 1 5 C 2 6 P 4 7 P 5 8 C 3 9 C 4 10 C 5 11 P 6 12 C 6 After which steps does P and/or C sleep? What is in the buffer after each step? After determining the answers to these questions? identify the true statement in the list below. a) The buffer holds 3, 4 between steps 8 and 9. b) The buffer holds 1, 2 between steps 4 and 5. c) P sleeps between steps 4 and 5. d) P sleeps between steps 7 and 8. Does anybody know the answer or can give me a bried explanation of it? thanks,
Maybe this will clarify things. For (1), you have initial values: M = 1 E = 10 F = 0 Process P can be in one of 4 states: (A) Before E has been decremented. (B) After E has been decremented, before M has been decremented (C) After M has been raised, before F has been raised (in critical region) (D) After F has been raised Similarly, C can be in one of 4 states: (A) Before F has been decremented (B) After F has been decremented, before M has been decremented (C) After M has been raised ,before E has been raised (in critical region) (D) After E has been raised So, collectively, P-C can be in 16 possible states (A-A, A-B, ... D-C, D-D). Each of those states implies a certain arithmetic relationship between M, F, and E. The patterns should be simple to figure out (e.g. if its A-A, then M=1, and E+F=10). Find which of a, b, c, or d is impossible. For (2), you know the buffer capacity is at most 2. So, for example, when P tries to produce 3 straight items without the C consuming anything, it will have to sleep prior to the third one (there's no room in the buffer for it). Following that, this question should be straightforward to answer.
thanks for the reply I kinda have a better understand from what you wrote but not so clear for me to figure it out. Tell me if I'm wrong: I have 1) A and 2)D in 1 could M every be = 0?
I made a mistake before in describing the 4 states. For Producer: (A) prior to decrementing E or after raising F, (B) prior to decrementing M, (C) prior to raising M (in critical region), (D) prior to raising F. For Consumer: (A) prior to decrementing F or after raising E, (B) prior to decrementing M, (C) prior to raising M (in critical region), (D) prior to raising E. Producer and consumer can not both be in state C at the same time. It would probably be helpful for you to draw out the state machine. If they're both in A, then M=1 and E+F = 10. From there, it's possible to producer and/or consumer to transition to B. This would means M=1, and E+F=9 (if one is in B) or E+F=8 (if both are in B). Next, only one can go on to state C. In this state, M=0, and (still) E+F=9 or E+F=8. Then, either producer or consumer goes to state D, allow the process that might be stuck in B to transition to C. The producer (or consumer) eventually goes back to A, then E+F=10 (if the other process is in A) or E+F=9 (if other process is in B, C, or D). Here's an example when producer is in state D: Prod-Consumer = D-A Then, M=1, E+F=9 Producer-Conumer = D-B Then, M=1, E+F=8 Producer-Consumer = D-C Then, M=0, E+F=8 Producer-Consumer = D-D Then, M=1, E+F=8 I think that should be enough for you to answer question 1 (hint: reconsider your answer).