Point where we will begin on 1/14/98
Declare a shared memory location to represent a busyflag on the critical section we are trying to protect.
waitloop: tsl busyflag, R0 // R0 = busyflag; busyflag = 1
bnz R0, waitloop // was it already set?
busyflag = 0
Associated with the lock is a memory location (busy) and a queue for waiting threads/processes.
while (busy) {enqueue caller on lock's queue}
/*upon waking to nonbusy lock*/ busy = true;
busy = false;
/* wakup */ move any waiting threads to Ready queue
Well-known synchronization abstraction
Defined as a non-negative integer with two atomic operations
P(s) - [wait until s > 0; s--]
V(s) - [s++]
The atomicity and the waiting can be implemented by either busywaiting or blocking solutions.
There are a number of "classic" problems that represent a class of synchronization situations
Producer:
while(whatever)
{ locally generate item
/* fill in synchronization*/
fill empty buffer with item
/* fill in synchronization*/
}
Consumer:
while(whatever)
{
/* fill in synchronization*/
get item from full buffer;
/* fill in synchronization*/
Use item; }
Template for Philosopher
while (food available)
{ /*pick up forks*/
eat;
/*put down forks*/
think awhile;
}