edited by
4,351 views
21 votes
21 votes

A certain processor provides a 'test and set' instruction that is used as follows:

  TSET register, flag

This instruction atomically copies flag to register and sets flag to $1$. Give pseudo-code for implementing the entry and exit code to a critical region using this instruction.

edited by

6 Answers

Best answer
18 votes
18 votes

 

  1. TSET $R1$, flag
  2. CMP $R1, \#0$
  3. JNZ Step$1$
  4. $[CS]$
  5. Store $M[Flag], \#0$
edited by
13 votes
13 votes

Q-2)

for consumer part

if (count==0)

consumer understands that buffer is full,But before consumer going  to sleep It got preempted and went to the Ready Queue

when producer produce an item and make Count=1,it will think consumer is blocked and try to wake up the consumer.

But actually Consumer is not Blocked it is in ready queue

After Some time Consumer come and Go to sleep[as before preemption it had seen that buffer is empty]

producer think that he has woken up consumer  and consumer is busy in consuming its produced item and consumer is waitinng for producer wakeup call

After sometime when buffer is full,producer went to sleep  thinking that when buffer is empty consumer will wake him up .And consumer is still waiting for producer wakeup call

So now Both are sleeping nd deadlock happens.

After some

edited by
3 votes
3 votes
part b) Initially when buffer is empty consumer reads count value =0  at that instant scheduler stops consumer temporarily and start producer process..Producer after inserting item finds count=1 and goes to sleep...Wakeup call of producer is lost and consumer finds count value =0 and go to sleep...so both are sleeping at same time
2 votes
2 votes

Q1. ENTRY SECTION (Assuming flag is set to 0 initially before any process entered critical section)

while(register!=0)
    Test(register, flag);

EXIT SECTION

f=0;

Related questions

29 votes
29 votes
4 answers
3
Kathleen asked Sep 23, 2014
13,177 views
Booth's coding in $8$ bits for the decimal number $-57$ is:$0-100+1000$$0-100+100-1$$0-1+100-10+1$$00-10+100-1$
35 votes
35 votes
4 answers
4
Keith Kr asked Sep 12, 2014
14,372 views
The minimum number of record movements required to merge five files A (with $10$ records), B (with $20$ records), C (with $15$ records), D (with $5$ records) and E (with ...