Synchronisation Hardware
Synchronisation Hardware
HARDWARE
TARUN KUMAR
[email protected]
CS Problem Dynamics
General structure of
process Pi (other is Pj)
do {
entry section
critical section
leave section
remainder section
} while (TRUE);
Solution to CS Problem
Mutual Exclusion
2.
Progress
3.
Bounded Waiting
Mutual Exclusion
If process Pi is executing in its critical section, then no other
processes can be executing in their critical sections.
Implications:
Progress
If no process is executing in its critical section and
there exist some processes that wish to enter their
critical section, then the selection of the process that
will enter the critical section next cannot be postponed
indefinitely:
Bounded Waiting
A bound must exist on the number of times that other
processes are allowed to enter their critical sections
after a process has made a request to enter its critical
section and before that request is granted.
Synchronization Hardware
TestAndSet Instruction
Definition:
boolean TestAndSet (boolean *target)
{
boolean rv = *target;
*target = TRUE;
return rv;
}
Swap Instruction
Definition:
void Swap (boolean *a, boolean *b)
{
boolean temp = *a;
*a = *b;
*b = temp:
}
Bounded-waiting Mutual
Exclusion with TestandSet()
do {
waiting[i] = TRUE;
key = TRUE;
while (waiting[i] && key)
key = TestAndSet(&lock);
waiting[i] = FALSE;
// critical section
j = (i + 1) % n;