Aptitude Overflow
+1 vote
375 views
  1. Draw the process state transition diagram of an OS in which (i) each process is in one of the five states: created, ready, running, blocked (i.e., sleep or wait), or terminated, and (ii) only non-preemptive scheduling is used by the OS. Label the transitions appropriately.
  2. The functionality of atomic TEST-AND-SET assembly language instruction is given by the following C function
    int TEST-AND-SET (int *x)
    {
        int y;
        A1: y=*x;
        A2: *x=1;
        A3: return y;
    }

     

  1. Complete the following C functions for implementing code for entering and leaving critical sections on the above TEST-AND-SET instruction. 
  2. int mutex=0; 
    void enter-cs() 
    { 
        while(......................); 
        
    } 
    void leave-cs() 
    { .........................; 
        
    }

     

  3. Is the above solution to the critical section problem deadlock free and starvation-free?
  4. For the above solution, show by an example that mutual exclusion is not ensured if TEST-AND-SET instruction is not atomic?
asked in Operating System by (58.9k points)  
retagged by | 375 views

1 Answer

+3 votes
B.
i-  1st blank- TestandSet(mutex).
     2nd blank- mutext=0;

ii - no.

iii-  say given procedure is not atomic. 1st execute process p1. After A1 p1 is preempted. 2nd process p2 now executes full code and enters critical section.  P1 resumes and completes the code and enters critical section. So 2 processes are now in critical section.
answered by (149 points)  
is this deadlock free??why and why not??
It is deadlock free but not starvation free.

Related questions

2,095 questions
812 answers
337 comments
15,411 users