CS3013 Homework 2

Due date: Thursday, September 18th

You must turn in your homework in written form by the beginning of class on the date it is due. Note, there are no late-dates allowed for this homework since a solution will be posted the afternoon it is due to help with mid-term exam preparation.

The questions are based on material presented in class and reading material from the text.


Give brief answers to the following questions:

  1. Given the following set of processes with their CPU burst times:

       Process       Burst Time
         A             5
         B             7
         C             4
    

    Assume processes arrive in the order A, B, C at times 0, 1, and 2 respectively. Draw a Gantt chart and compute the average waiting time for Round Robin (RR) scheduling with time slice 2 (do not have idle time slots).

  2. When is the Windows NT/2000 scheduler like the basic Round-Robin scheduler as presented in class?

  3. Explain in what ways a software interrupt is similar to a hardware interrupt. Explain in what ways it is different.

  4. What is a critical section? What are the three requirements for correctly solving a critical section problem?

  5. Both busy waiting and blocking methods can be used as means to address critical section problems and process synchronization. Describe how blocking is different from busy waiting, and discuss the advantages and disadvantages of each.

  6. Suppose your OS does not yet have semaphores but the computer system does have the Test_and_Set() function. Assuming only a single semaphore is needed, implement the functions wait(void) and signal(void) using the Test_and_Set() function. You may use a shared boolean variable called "lock". What are the potential drawbacks, if any, of this semaphore implementation?

  7. Do semaphores solve the problem of process synchronization completely? What are some of the things that might still go wrong in a solution that requires synchronization?

  8. What is a monitor? Explain how it can be used to solve a synchronization problem.

  9. Following is an implementation of a mailbox that can contain one message at a time. Use semaphore(s) to make the consumer prints the message once if and only if there is a message in the mailbox created by the producer.

            struct message mbox;   /* shared */
    
            producer() {
    
              struct message my_msg;
    
              while(1) {
                create_msg(&my_msg);     /* create my message */
    	    put_msg(mbox, my_msg);   /* put my message in the mbox */
              }
            }
    
            consumer() {
     
              struct message my_msg;
    
              while(1) {
                get_msg(&my_msg, mbox);  /* get message from the mbox */
    	    print_msg(my_msg);       /* print my message */
              }
            }
    

  10. Consider the following solution for the Dining Philosophers for 6 philosophers:

            semaphore chopstick[6];  /* shared array of sems */
            while (1) {
              /* think */
              wait(chopstick[i]);
              wait(chopstick[i+1 % 6]);
              /* eat */
              signal(chopstick[i+1 % 6]);
              signal(chopstick[i]);
            }
    

    What is a potential problem with this solution? Modify the above solution to avoid deadlock by allowing only a philosopher to "sit" in every alternate chair. You may declare additional semaphores as needed and shared variables as needed.


Return to the CS3013 Home Page

Send all questions to the TA mailing list.