void XCHG(bool *X, bool *Y) {
bool tmp = *X;
*X = *Y;
*Y = tmp;
}
Show how XCHG can be used instead of test-and-set to implement the acquire() and release() functions of the lock data structure described in the "Synchronization" lecture.
struct lock {
...
}
void acquire (struct lock *) {
...
}
void release (struct lock *) {
...
}
Implement Event using a mutex and conditon variable. The mutex and condition variable have the semantics described at the end of the "Semaphore and Monitor" lecture in the ping_pong example, and as implemented by you in Project 1.
class Event {
...private variables...
void Signal () {
...
}
void Wait () {
...
}
}