in Operating System
254 views
0 votes
0 votes

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
in Operating System
by
254 views

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?
1
1

2 Answers

0 votes
0 votes

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)

 

–1 vote
–1 vote
Answer is - a) i only

2 Comments

please explain your answer
4
4
Test_and_set is not given atomic here
0
0
Answer:

Related questions