in Operating System edited by
5,095 views
4 votes
4 votes

The hardware implementation which provides mutual exclusion is

  1. Semaphores
  2. Test and set instructions
  3. Both options
  4. None of the options
in Operating System edited by
by
5.1k views

1 comment

What about counting semaphores?
0
0

4 Answers

10 votes
10 votes

B is correct.

TSL is obviously hardware solution.

Regarding Semaphores

It needs kernel support to make P and V operation atomic but hardware support isn't essential.

Both P & V operations must be indivisible. (essential)

 

Suggestions for making P and V indivisible (Anyone is sufficient)

To make these operations indivisible we could:-

  • Treat them as critical sections and use our N process software solutions at entry and exit to the P & V operations.
  • Use hardware instructions test and set or swap to implement spin locks for access to P and V.
  • Implement P and V within operating system code and turn off interrupts during their execution.
  • Use the java language synchronisation features to ensure mutually exclusive execution of P and V among threads.

Ref: http://www.cs.nuim.ie/~dkelly/CS240-05/ProcessSynchronisation3.htm?fbclid=IwAR3qPO65T8d40P7uvbZHGwawRstYIf_e6LL4xLORlAjIudTrVkzs2Od7ZPU

edited by
5 votes
5 votes

$\underline{\textbf{Answer:}\Rightarrow\;}\;\mathbf{c.}$

Semaphore means hardware or software flag.

Test and set is a hardware implementation.


https://en.wikipedia.org/wiki/Test-and-set

https://en.wikipedia.org/wiki/Semaphore_(programming)

edited by
by

2 Comments

Wiki is not a reliable source
1
1
Semaphore guarantees nothing ..you implement it in bad way and there will be no mutual exclusion or infact deadlock ... but test and set instructions is a std implementation in hardware mode!
0
0
0 votes
0 votes
Test and Set instruction  ensures entry of critical section mutual exclusively. When a process is testing and set instruction and lock the testing before entering into critical section. No other process can test the lock variable unless existing process exit the critical section and set the test and set instruction FREE. So it ensures mutual exclusion to avoid dead lock. Hence the option (B) is appears correct.

1 comment

edited by
Semaphore is a software based mechanism. Any OS has a piece of software through which it handles(supports)the semaphore. So option B is correct.

EDIT: Some typos.
0
0
0 votes
0 votes

Option B  TSL instruction

Semaphore is a OS implementation of synchronization,

TestAndSet is a special machine instruction to provided hardware solution to critical section problem.

The definition of the TestAndSet () instruction.

boolean TestAndSet(boolean *target)

{

boolean rv = *target;

*target = TRUE;

return rv;

}

Mutual-exclusion implementation with TestAndSet ()

do {

while (TestAndSet(&lock)) ;

//do nothing

//critical section

lock = FALSE;

// remainder section

} while (TRUE);

The important characteristic of this instruction is that it is executed atomically. Thus, if two TestAndSet () instructions are executed simultaneously (each on a different CPU), they will be executed sequentially in some arbitrary order. If the machine supports the TestAndSet () instruction, then we can implement mutual exclusion by declaring a Boolean variable lock, initialized to false.

Answer:

Related questions