Exam 1
Exam 1
Name: _________________________
Question Number
1
2
3
4
5
6
7
Total:
Score
Question1:
Explain the following terminology: (3pts each)
1.
2.
3.
4.
5.
6.
7.
Process
I/O-bound process
Symmetric multiprocessing
spinlock
Adaptive mutexes
Race Condition
Monitor
Question2:
2.1 Explain and describe 3 different types of processes scheduler, also, draw
a graph (include all schedulers and queues) to indicate the relation between 2
different queues and processes schedulers. (5 pts)
Long-term scheduler
(or job scheduler) selects which processes should be brought into the
ready queue
Short-term scheduler
(or CPU scheduler) selects which process should be executed next and
allocates CPU
Midterm Scheduler
Sometimes it can be advantage to remove process from memory and thus
decrease the degree of multiprogrammimg. This scheme is called
swapping
2.2 Describe 3 different multithreading models for mapping user threads to
kernel threads. Also, describe one advantage or disadvantage for each
model. (5 pts)
Many to one: It maps many user-level threads to one kernel thread. The
entire system may block makes a block system call.
One to one: Each user-level thread has one corresponding kernel thread.
The only drawback is that creating a user thread requires creating the
corresponding kernel thread
Many to many: Multiplexes many user-level threads to a smaller or equal
number of kernel threads. User can create as many threads as they want
Question3:
According to the bounded buffer code in shared memory system we
discussed in the class, draw the ring structure with size 4 and indicate the
location of in and out for each time space. (If the buffer is full or empty,
indicates how many jobs are waiting) (10pts, 2 pts for each)
Producer View
while (true) {
/* produce an item and put in next Produced*/
while (count == BUFFER_SIZE)
; // do nothing
buffer [in] = nextProduced;
in = (in + 1) % BUFFER_SIZE;
count++;
}
Consumer View
while (true) {
while (count == 0)
; // do nothing
nextConsumed= buffer[out];
out = (out + 1) % BUFFER_SIZE;
count--;
/* consume the item in next Consumed
}
Time
1
Action
Producer produces 3 jobs
in:1
4
out:1
1
Question4:
In the MPI programming we discussed in the class (also showed below), P0 (the id for CPU is 0) is the
server who owned the full array and distributed array information to other CPUs. For other CPUs, they
wait for receiving those data.
__________________________________________________________
if (id==0)
{
for(i=0; i<array_size; i++)
array[i]=i; /* initialize array*/
for(i=1; i<p; i++)
MPI_Send(&array[i*array_size/p], /* Start from*/
array_size/p,
/* Message size*/
MPI_INT,
/* Data type*/
i,
/* Send to which process*/
MPI_COMM_WORLD);
for(i=0; i<array_size/p; i++)
local_array[i]=array[i];
}
else
MPI_Recv(&local_array[0],array_size/p,MPI_INT,0,0,MPI_COMM_WORLD,&stat);
Assume we have 8 CPUs, the network of those CPUs looks like below:
Instead of using P0 as the only master; we use both P0 and P6 as the masters. (P0 is the master for P0
through P3; P6 is the master for P4 through P7) Both of them generate the initial array only for their
responsibility portion. Write a code similar to I showed you above that matches the criteria. Every line
above should have a corresponding line(s) in your answer. (15 pts)
If (id==0){
for (i=0; i<array_size/2;i++)
array[i]=i;
for (i=1; i<4; i++)
MPI_Send(&array[i*array_size/p], array_size/p, MPI_INT, i, MPI_COMM_WORLD);
for (i=0; i<array_size/p; i++)
local_array[i]=array[i];
}
If (id==6){
for (i= array_size/2; i<array_size;i++)
array[i]=i;
for (i=4; i<7; i++)
if (i != 6)
MPI_Send(&array[i*array_size/p], array_size/p, MPI_INT, i, MPI_COMM_WORLD);
for (i=0; i<array_size/p; i++)
local_array[i]=array[2* (array_size/p) + i];
}
if (id==1 or id==2 or id==3)
MPI_Recv(&local_array[0],array_size/p,MPI_INT,0,0,MPI_COMM_WORLD,&stat);
if (id==4 or id==5 or id==7)
MPI_Recv(&local_array[0],array_size/p,MPI_INT,6,0,MPI_COMM_WORLD,&stat);
Question 5:
By Multilevel Queue Fixed priority scheduling algorithm, draw the CPU
scheduling Gantt chart and complete the table for the give processes
information. (15 pts)
Process
1st Foreground
Burst time
Arriving time
P1
P2
P3
50
15
45
0.0
30.0
30.0
2nd Foreground P4
P5
40
10
0.0
120.0
30
20
60.0
130.0
Background
P6
P7
Algorithm
RR interval:20
(RR is a non-preemptive
algorithm)
SJF Preemptive
FCFS
Gantt chart:
Waiting time
Turnaround time
Response time
P1
35
85
0
P2
10
25
10
P3
35
80
25
P4
120
160
110
P5
0
10
0
P6
100
130
100
P7
60
80
60
Question6:
6.1 A solution to the critical-section problem must satisfy which three requirements?
(6pts)
Mutual Exclusion
Progress
Bounded Waiting
6.2 We consider a system consisting of two processes, P0 and P1, each accessing two
semaphores, S and Q, set to the value 1.
P0
Wait(S)
Wait(Q)
Signal(S)
Signal(Q)
P1
Wait(Q)
Wait(S)
Signal(Q)
Signal(S)
What kind of unwanted situation will happen? (3%) Explain your answer? (3%)
Deadlock Occurs
6.3 We consider a system consisting of two processes, P0 and P1, each accessing two
semaphores, S and Q, set to the value 1.
P0
Wait(S)
Wait(Q)
Signal(S)
Signal(S)
P1
Wait(S)
Wait(Q)
Signal(Q)
Signal(S)
What kind of unwanted situation(s) will happen? (4%) Explain your answer? (4%)
Starvation (Deadlock)
Violate Mutual exclusion
Question7:
If we applied timestamp-Based Protocols on the following schedule:
Timestamp:
Operation:
T0
2
R(A)
W(A)
T1
4
R(A)
T2
6
R(A)
W(A)