Question: Write a synchronization solution to the below scenario using semaphores only: [2Marks] Assumptions: The arcs in the chart below illustrate the processes dependencies. The CPU
Write a synchronization solution to the below scenario using semaphores only: [2Marks]
Assumptions:
- The arcs in the chart below illustrate the processes dependencies.
- The CPU can start with any process [keep in mind that always the subprocesses execute in a sequential order ex: the CPU never select to execute p2.2 before p2.1].
- The semaphores are used to ensure that the processes will execute in any sequence but within the suggested dependencies in the chart.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Code |
|
|
| P |
| 3 |
| .1 |
|
|
| Code |
|
|
| P |
| 2 |
| . |
| 1 |
|
|
| Code |
|
|
| P1. |
| 1 |
|
|
| Code |
|
|
| P |
| 3 |
| .2 |
|
|
| Code |
|
|
| P1. |
| 2 |
|
|
Answer:
| //Shared variables /*Put your semaphores declaration & initialization below this line */
| ||
| //Process 1 do{
Code p1.1
Code p1.2
}while(true);
[0.25 mark] | //Process 2 do{
Code
}while(true);
[0.25 mark] | //Process 3 do{
Code
Code ;
}while(true);
[0.25 mark] |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
