Beruflich Dokumente
Kultur Dokumente
COURSE:
CSI3131
INSTRUCTOR:
Stojmenovic
DATE:
2013
TIME:
Ivan
February 12,
16:00 to 17:00
MIDTERM EXAMINATION
/
_
Mid-Term Exam
This is closed book exam. There are three (3) types of questions in this examination.
Part 1
Part 2
Part 3
Total
Multiple choice
Short answer
Problem solving
9 marks
21 marks
20 marks
50 marks
Answer briefly and to the point. The space allocated for each question is limited. In case
of necessity you may use the back side of the pages to continue and indicate as such.
Page 1 of 10
One of the following is true about using interrupt disabling for protecting critical sections:
a)
b)
c)
d)
e)
2. The following proposed solution for the critical section problem with several processes uses
the exchange machine instruction:
Shared variable b is initialized to 1
Process Pi:
repeat
k:=0
repeat {xchg(k,b)} until k=1;
critical section
b:=1;
remaining section
forever
One of the following is true:
a)
b)
c)
d)
e)
It guarantees mutual exclusion but does not guarantee progress and bounded waiting
It is a valid solution to the critical section problem
It does not guarantee mutual exclusion
It may lead to deadlock
None of these answers
3. Consider the following processes that are synchronized with two semaphores:
Initialization: S1.count := S2.count := 0;
Process P1
Statement1;
signal(S1);
Process P2
wait(S1);
Statement2;
signal(S2);
Process P3
wait(S2);
Statement3;
Page 2 of 10
Page 3 of 10
8. For each of the following statements, mark the appropriate answer (True or False):
(2 points)
a) When a thread calls exec(), the new process gets a copy of each thread of the parent
process. [F] (that might be the case with fork() ,but exec() replaces all threads with a
new process, starting with a single thread)
b) Deferred cancellation is used to postpone the cancellation of a process until its parent is
ready to accept the exit value. [F] (deferred cancellation tells the thread/process to
terminate, it is up to the thread to do that, the parent has nothing to do with that)
Page 4 of 10
Short-answer questions:
1. (5 points) For the following transitions in the 5-state process diagram, identify if it is
possible, and if, so, list how it occurs.
New to running _____________false___________________
Ready to terminated __________false________________________________________
Waiting to ready ______________I/O or event completion ______________________
Ready to running _____________scheduler dispatch ___________________________
Running to ready ____________ interrupt____________________________________
2. (3 points) Describe the three multithreading models.
Many-to-one model: maps many user-level threads to one kernel thread. Thread
management is done by the thread library in user space. The entire process will block if a
thread makes a blocking system call. Because one thread can access the kernel at a time,
multiple threads are unable to run on multiprocessors.
One-to-one model: maps each user thread to a kernel thread. It provides more
concurrency than the many-to-one model by allowing another thread to run when a
thread makes a blocking call; it also allows multiple threads to run in parallel on
multiprocessors.
Many-to-many model: multiplexes many user-level threads to a smaller or equal number
of kernel threads. Developers can create as many user threads as necessary, and the
corresponding kernel threads can run in parallel on a multiprocessor.
3. (3 points) Describe three requirements a solution to Critical Section Problem must satisfy.
Mutual exclusion: only one process can be in the critical section at any moment of time
Progress: if some processes want to enter the CS and there is no process in the CS,
eventually one of the processes will enter the CS.
Bounded Waiting: (starvation free) a process waiting to enter the CS can be overtaken
only finite number of times before being give access to the CS
4. (2 points) The following algorithm proposes an approach for dealing with the critical
section problem (for two tasks Ti and Tj; a task can represent either a process or a
Page 5 of 10
thread). Does it provide a suitable solution? Justify your answer (argue why it is a
solution, or identify which requirements of the CSP are violated and show how).
Task Ti:
while
{
flag[i]=true
while(flag[j]!=true){};
Critical Section
flag[i]=false;
Remainder Section
}
Task Tj:
while
{
flag[j]=true
while(flag[i]!=true){};
Critical Section
flag[j]=false;
Remainder Section
}
Page 6 of 10
In Kernel mode, the executing code has complete and unrestricted access to the
underlying hardware. It can execute any CPU instruction and reference any memory
address. Kernel mode is generally reserved for the lowest-level, most trusted functions of
the operating system. Crashes in kernel mode are catastrophic; they will halt the entire
PC.
In User mode, the executing code has no ability to directly access hardware or reference
memory. Code running in user mode must delegate to system APIs to access hardware or
memory. Due to the protection afforded by this sort of isolation, crashes in user mode are
always recoverable. Most of the code running on your computer will execute in user
mode.
Page 7 of 10
10
15
20
25
30
FCFS: p1 (0, 5), p2 (5, 6), p3 (6, 7), p4 (7, 9), p5(9,19)
10
15
20
25
30
SJF: p1 (0, 5), p2 (5, 6), p3 (6, 7), p4 (7, 9), p5(9,19)
10
15
20
25
30
Page 8 of 10
RR: 1
2. (10 points) In the solution presented in class, a philosopher eats if his/her neighbors do not eat
and he/she is hungry. This assumes that the philosopher is attempting to grab only two chopsticks
which are to his/her left and the right side. Solve the same problem where philosopher looks for
any two chopsticks on the table. In other words, at most two philosophers could eat
simultaneously, and they could be neighbors.
Thus 5 philosophers think, eat, think, eat, think . In the center is a bowl of rice. Only 5
chopsticks are available. Philosopher requires any two chopsticks for eating.
Define the monitor dp (dining philosophers). It has shared variables. Each
philosopher has its own state that can be: (thinking, hungry, eating). Philosopher i can
only have state[i] = eating if and only if (s)he picks up two chopsticks that become
available.
Conditional variables: each philosopher has a condition self
the philosopher i can wait on self[i] if (s)he wants to eat but cannot obtain 2
chopsticks
Four functions in the monitor
pickup(i) philosopher i wants to pick up chopsticks
putdown(i) philosopher i puts down his/her chopsticks
test(i) test the state of philosopher i
Initialization_code() - initialization
Philosopher i executes the loop:
while(true)
{
think
dp.pickup(i)
eat
dp.putdown(i)
}
void test(int i) {
if((state[i]==hungry) && (Chopsticks>=2))
{
Page 9 of 10
State[i]=eating;
Chopsticks--;
Chopsticks--;
Self[i].signal();
}
}
void pickUp(int i){
state[i]=hungry;
test(i);
if(state[i] !=eating)
Self[i].wait();
}
void putDown(int i){
state[i]=thinking;
test((i+1)%5);
test((i+2)%5);
test((i+3)%5);
test((i+4)%5);
}
Mutual exclusion: Yes, though two philosophers eat simultaneously, only one modified
chopsticks at one time.
Progress: No deadlock.
Bounder waiting: It is possible for a philosopher to starve to death.
Page 10 of 10