1. A process may be in one of 5 states. Name each state with a short description.
2. What should be in the PCB? Why?
3. List 4 instructions that should be privileged, and why.
For example, you can include "turn off all interrupts".
4. Do you want to program on a system that uses thread model many-toone, one-to-one, or many-to-many? Why?
5. In lecture we said that, if the semaphore operatons Wait and Signal
are not executed with certain atomic instructions, then mutual exclusion
might be violated. Assume Wait and Signal are implemented as:
void semWait(semaphore S) {
while (S.count <=0) ;
S.count = S.count -1;
}
void semSignal(semaphore S) {
S.count = S.count +1;
}
Describe a sequence of events where two threads could both be in
a critical section of code guarded by a single mutex semaphore as a
result of a lack of atomicity.
Give another version of code that will work, mark which instructions need to be executed atomically.
Question 5 answers
6. What thing are you happiest that you have learned so far this semester in this course? Describe it. What can you do now that you know it? (Maybe a concept, maybe an increase vocabulary, etc. It have have caused you to say, "Oh,
that is how that works!", "Oh, that is what that means!", etc.)
Be sure your answer is in your own words and is enough to prove you understand whatever you claim to have learned.
7. List your group members for project 1. Briefly describe the most challenging bug that your group enountered in project 1, how your group found it, and how long it took your group to find it. Which of your group members do you think will give the best answer to this question?
8. Question 8 text You can use any synchronization IPC method we covered in class. You can use pseudo-ish code or actual code.
If you use semaphores and pseudo code,
Declare a semaphore as: semaphore theNameYouPick;
Initialize a semaphore as: theNameYouPick=initialValue;
Wait on a semaphore as: semWait(theNameYouPick);
Signal on a semaphore as: semSignal(theNameYouPick);
You may want to write something in the answer box and occationaly "preview" it to prevent blackboard from timing out. You may also want to keep a copy of your answer as it develops on your local machine in case of a system crash.
State any references you use.
A bridge is undergoing repairs and only one lane is open for traffic.
To prevent accidents, traffic needs to be synchronized.
A car can only cross the bridge if there are no cars going in
the opposite direction on the bridge. (A car can begin to cross the
bridge if going with the current flow of traffic.)
Sensors at either end of the bridge detect when cars arrive
and depart from the bridge and these sensors control traffic lights.
Consider a partial solution:
sharedmemory int numCars=0;
enum trafficDirection={open, north, south}
sharedmemory trafficDirection currentDir=open;
Car(trafficDirection desiredDir) {
pid_t pid=getpid();
printf("car %d wants to go %d\n", pid, desiredDir); /* I know, I know ... pretend it prints ok */
Arrive(desiredDir);
printf("car %d is traveling %d on the bridge\n", pid, desiredDir); /* I know, I know ... pretend it prints ok */
/* take some time to travel */ sleep 1;
Depart(desiredDir);
printf("car %d is off the bridge\n", pid);
}
Arrive(trafficDirection desiredDir){
while (currentDir != desiredDir || currentDir != open);
numCars++;
currentDir=desiredDir;
}
Depart(trafficDirection desiredDir) {
numCars--;
if (numCars==0) currentDir=open;
}
Consider a main program that starts a bunch of Cars randomly picking which
direction they want to travel in.
PART A:
The code above does not have any synchronization statements.
Give an interleaving of some (for example of 2 processes) which would
cause a collision (two cars traveling on the bridge in opposite directions
at the same time).
PART B:
Add synchronization to avoid collisions. (Use psuedo code, but express
all the important steps: declaration, initialization, etc.). Give your
improved program below.