256 views

The E_CS() and L_CS() functions to implement critical section of a process are realized using Test-and-Set instruction as stated below:

void E_CS(X)
{
while(Test-and-Set(X);
}
void L_CS(X)
{
X=0;
}

In above code snippet, X is a memory location associated with CS and is initialized to 0. Which among these statements are True regarding the given solution?

1. it is deadlock free solution
2. it is starvation free solution
3. the process enter into CS in FIFO order
4. more than 1 process can enter into CS at same time
1. i only
2. i and ii
3. ii and iii
4. iv only

### 1 comment

here no process is setting X=1, so everytime any process comes, sees X=0 and enters in Critical section.So seems like option D is answer.

Can someone please explain why it is option A?

Given in the question, process are realized using Test-and-Set instruction

Test-and-Set instruction → an instruction used to write 1 (set) to a memory location and return its old value as a single atomic (i.e., non-interruptible) operation.

So , given module E_CS(X) will work as as wait function (P) AND L_CS(X) as signal/wakeup function (V).

Here 1 value of X means wait state And 0 means free (complement of what we normally use for semaphores)

So the given implementation is deadlock free (due to atomicity of Test-and-Set instruction) .

Here since there’s no bounded waiting (any process can be given CS no scheduling/queue), Hence starvation is possible.

So answer should be option (A)

by
Answer is - a) i only

Test_and_set is not given atomic here

1 vote