// pingcvtest.cc // // Simple test case for condition variables. // Alternate two threads, one that prints "ping" and another that // prints "pong". #include "copyright.h" #include "system.h" #include "synch.h" Lock *mutex; Condition *cv; void PingPong(int which) { char *msg = (char *) which; int i; mutex->Acquire(); for (i = 0; i < 20; i++) { printf("%s...", msg); cv->Signal(mutex); cv->Wait(mutex); } mutex->Release(); } void ThreadTest() { DEBUG('t', "Entering ThreadTest"); mutex = new Lock("mutex for cv"); cv = new Condition("ping pong cv"); char *ping = "ping"; char *pong = "pong"; Thread *t = new Thread(ping); t->Fork(PingPong, (int) ping); PingPong((int) pong); printf("\n"); }