Define test and set instruction in operating system.
The TestAndSet() is a special instruction, which can be used to solve the
critical section problem in a simple way. Typically, TestAndSet() is a function, which is executed atomically. It uses single shared variable known as lock variable. When a process wants to enter its critical section, it first checks the value of lock variable. If its value is 0, the process sets this value to '1'
and enters the critical section. If the lock is already 1, the process just
waits until the value of lock becomes '0' Thus, the value '0' of lock means
that no process is in its critical section, and '1' means that some process is
already in its critical section.
|