Question 3 (2,2, 1, 1) Consider a uniprocessor system executing concurrently two
ID: 3908708 • Letter: Q
Question
Question 3 (2,2, 1, 1) Consider a uniprocessor system executing concurrently two processes P and Q. Each process executes the code listed below, process P-procedure P, and process Q-procedure Q. Both processes arrive within a very short time of each other, but no assumptions can be made about the time they start execution and their relative speed. All statements used in the code below from A to K are atomic ie. they either execute completely or not at all. The execution of the processes is synchronised by two binary semaphores S1 and S2. The semaphore S1 is initialised to 1, and the semaphore S2 is initialised to 0. The code executed by the processes is as follows: procedure P begin procedure Q begin A; wait(S1): ?: signal(S1); F: wait(S1); G: H: D: signal(S2) signal(S1); wait(S2) K; E: end end a. Give at least four possible orders of execution for statements A to K What is the function of each of the semaphores S1 and S2 in the given example? Is it possible for statement E to execute before statement F? Justify your answer. Is it possible for statement K to execute before statement A? Justify your answer. b. C.Explanation / Answer
1. The four possible orders of execution are:
A,C,D,E,K
A,D,C,E,K
F,D,C,E,K
F,C,D,E,K
2. Functions of each semaphore
S1 - is used for waiting of process to execute its critical region
S2 - is used for signalling of process after its execution of critical region
3. IS it possible for E to execute before F?
Yes, It is possible for E to get executed before F provided there is a conditional statement present and also since both the processes are waiting for the signal from S2 semaphore.....which makes process Q keep on waiting.
4. IS it possible for K to execute before A?
Yes, It is possible for K to get executed before A provided there is a conditional statement present and also since both the processes are waiting for the signal from S2 semaphore.....which makes process P keep on waiting.
Feel free to ask if there is any doubt.
I have answered your question based on the data provided by you.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.