Final Exam Discussion

If you are creating new threads, please start your discussion here.

The comments on the other post is getting too long and confusing.

21 thoughts on “Final Exam Discussion

  1. Any suggestions for Qn4? My answer for this will be D. As disk is a shared resource. Multiple processes can read from the disk.
    The disk reads are many orders slower than memory reads. Also a disk read means that the process is blocked for IO. Therefore I think P will not be affected because its request is queued later than Q’s because in that scenario both processes are blocked for IO.

    • For Q4, I was wondering why process A would be encountering more page faults. Is it because we assume that the memory is large enough to hold only one process such that when two processes are running, process P may encounter page faults?

  2. Thanks Wen Kuan and Bang Hui’s comments, the updated code is:
    int current_class = -1, no_waiting_process = 0, no_active_process = 0;
    Semaphore m=1,w=0;

    enter_class(class){
    down(m);
    if(current_class == -1){
        current_class=class;
        no_active_process++;
        up(m);
     }
    else{
       if(current_class == class){
           no_active_process++;
           up(m);
        }
       else{
           no_wait_process++;
           up(m);
           down(w);
           enter_class(class);
      }
    }
    }
    
    leave_class(class){
    down(m);
    no_active_process--;
    if(no_active_process==0){
        int i;
        for(i=1;i<=no_wait_process;i++)
             up(w);
        no_wait_process=0;
        current_class =-1;
    }
    up(m);
    }
    

    (Again, Wei Tsang inserted the pre tag for clarify)

    • My solution to Qn 14.

      //declaration:
      semaphore mutex;
      semaphore sema[2];
      int count[2];
      
      //inits
      init(mutex, 1);
      init(sema[0], 1);
      init(sema[1], 1);
      
      enter_class(class):
      	down(mutex);
      	if (count[class] == 0)
      		down(sema[1 - class]);
      	count[class]++;
      	up(mutex);
      	down(sema[class]);
      	up(sema[class]);
      	
      leave_class(class):
      	down(mutex);
      	count[class]--;
      	if (count[class]==0)
      		up(sema[1 - class]);
      	up(mutex);
      

      The idea is that, the first process lock the other door and the last process unlock the other door. Use count[] to identify the first and the last, and sema[] serves as the lock. In enter_class(), the down() and up() is just to check.
      correct me if I am wrong.

  3. I really hate the way of this blog.
    It just make me and my friends EXTREMELY NERVOUS!!!
    at the night of the EXAM!!! for every minute there is a POST from both PROF and students with more and more new materials, codes, videos!!! and confusing notes.

    PLEASE STOP THIS BLOG!
    make it like other normal exams!
    My heart rate is very high right now!!

  4. I have something like this for q14
    it is similar to test&set lock

    I think some of the other solutions posted here doesn’t allow multiple processes of same class inside CR

    // enter:
    while(true) {
    down(mutex);
    if(count[1 – class] == 0) {
    count[class]++;
    break;
    }
    up(mutex);
    }
    up(mutex);
    // do stuff

Leave a Reply

Your email address will not be published. Required fields are marked *