The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
+2 votes

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() 
    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 Veteran (99.8k points) | 177 views

1 Answer

0 votes
entry condition : while( TESTANDSET(&mutex) )

exit condition : mutex=0;


yes above solution is deadlock free ony if reading and setting of mutex done atomically

I think it is not starvation free but I'm not sure about this
answered by Active (1.9k points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

37,980 questions
45,481 answers
48,453 users