I have a homework problem about the producer-consumer relationship, which I can't understand where to start from.
Here is the problem:
Please consider the producer-consumer relationship between processes and suppose that a process P1 sends a 5 byte message through buffer to process P2. P2 reads the string "SSNNEMANE NCATA" from the buffer, while the message P1 sent is "CONNESSIONE MANCATA". What can you say about their syncronization (realized with semaphores)?
Is anybody able to help? Thank you!
I think you mean sends a message through a 5 byte buffer. You only posted a fragment, but I think the idea is to look at what should have happened; and compare it to what did, to generate hypothesis about how the buffer is being corrupted.
For example, how could we get the buffer into a state where it contains SSNE:
Hypothesis1: The semaphore availability count is being used to represent free space in the buffer. That count has been incorrectly initialized to 7 rather than 5, so the sender is corrupting the buffer. In the steps above; step 3 is proceeding before step 2.
Hypothesis2: The availability semaphore (Hypothesis1) is incorrectly used as a mutex and both processes are over-writing the head and tail buffer pointers independently.
Hypothesis3: ...
Now, test that hypothesis against the pattern you see for consistency - could it generate the entire result.
Finally, examine the code to see if this is indeed the case.
Effectively repeat this procedure of generating hypothesis until you find the solution.