Questions from Exam 1 of previous semesters

  1. (4) Consider the dining philosophers problem. If we add a 6th chopstick to the center of the table, have we cured the deadlock problem? If yes, what condition have we removed? If no, explain why not.


  1. (6) Consider the dining philosophers problem. If we place all five chopsticks in the center of the table, how could we use semaphores to implement the philosophers eat() method? Be sure to declare and initialize all variables you use. Your solution should be as efficient as possible. You should define two methods begin() and end().


  1. (12) Describe the four necessary conditions for deadlock.


  1. (12) Describe four ways one might deal with deadlock with a brief description of each possibility and how it is achieved


  1. (12) Draw the labeled state diagram for a process and the transitions between them. Indicate which are preemptive

  1. (4) Explain the use of fork and how it is used to write a shell program.


  1. (4) Define a race condition and describe what is necessary for a race condition to occur.


  1. (4) Why don’t the methods of the java String, Integer, and Double classes need to be synchronized?


  1. (8) Describe the steps that the bankers algorithm uses to determine whether to grant a request


  1. (4) Describe the testAndSet instruction of a CPU. What type of blocking is normally used with this? When is this appropriate?


  1. (4) Describe two goals of an operating system and an example of something the operating system does to achieve that goal.


  1. (4) Define the terms “policy” and “mechanism” as they relate to operating systems and give an example of each.


  1. (6) Describe the three requirements for a critical section solution.


  1. (8) Given the following set of processes, draw the Gant chart for Priority scheduling.Be sure and state any assumptions you make in your solution. Calculate the average wait time for your solution



Process

Burst

Arrival

Priority

P1

5

2

1

P2

1

1

2

P3

8

3

3

P4

5

1

2

P5

6

4

4



  1. (8) What four facilities does Java provide for writing concurrent programs? Describe each.

  2. (4) What does the Java keyword synchronized mean when applied to a method?

  3. (4) Define/describe: context switch; swapping

  4. (4) Describe starvation with respect to scheduling. How can it be avoided?

  5. (12) Suppose the scheduler allowed the same process to exist multiple times in the ready queue. What would be the effect of this? What problem(s) might it introduce for the kernel? What alternative would achieve a similar effect?

  6. (4) Why are I/O bound processes often given priority over compute bound processes?

  7. (18) Peterson solution is shown below (see book) Define and show how the solution meets the three requirements for a critical solution.

  8. In Lab 1, there was a race condition in the constructor of NetFlip. Describe the threads that produced the race. Describe the result of the race condition. Describe how the race could be prevented.

  9. (8) The race condition in the previous problem resulted from a Java (OO) feature that could cause a problem even in a non threaded program. Describe the OO feature. Why could this be a problem?

  10. (4) Explain under what circumstances there is a transition (process state diagram) from ready to blocked.

  11. (4) Under what circumstances is there a transition from ready or blocked to terminated?

  12. (8) What is busy waiting? When is it appropriate?

  13. (4) Do “getters” (i.e. methods that only “read” values) ever need to be synchronized? If yes, why? If no, why not?

  14. (16) Name and describe each of the four necessary conditions for deadlock and illustrate with an example from the dining philosophers problem.

  15. (8) Consider the following three threads and assume x and y are initially 0. Describe the race conditions in terms of these threads. Be specific. Using semaphore(s), initialized appropriately, add code to insure that thread T1 prints the value 3. You may assume the semaphores are initialized before any threads begin. Thread T1: print(x+y); Thread T2: x=1; Thread T3: y=2;

  16. (8) The bank check clearing facility run 1000’s of threads that reconcile checks. The form of the code they run is given below. Describe the problem this code might encounter with a description of how the problem occurs. How would you add modify code to fix the problem


          public void transfer (BankAccount from, BankAccount to, int amount) {
            synchronized(from) {
              synchronized(to) {
                from.withdraw(amount);
                to.deposit(amount);
              }
            }
          }

  1. (12) Four tasks have the following task information. A trace of the execution shows a Gant chart of ABBBBCBCBCCDDAAA. Fill in the waiting time for each process. Describe four characteristics you can deduce from the given information. Be Specific





Process

Arrival

Length

Priority

Waiting Time

A

0

5

3


B

1

6

8


C

4

4

8


D

6

2

3



  1. (8) A system has four processes and five allocatable resources. The current allocation and maximum needs are given. Show that 2 is the samllest value of x for which this is a safe state.

    Processs

    Allocated

    Maximum

    Available

    A

    1 0 2 1 1

    1 1 2 1 3

    0 0 x 1 1

    B

    2 0 1 1 0

    2 2 2 1 0


    C

    1 1 0 1 0

    2 1 3 1 0


    D

    1 1 1 1 0

    1 1 2 2 1