#include #include #include // Counting Semaphore initialized to 10 CountingSemaphore sem1; class Daughter : public Thread { public: Daughter() { } protected: void Run(void) { cout << "This is a daughter" << endl; sleep(3); sem1.V(); } }; int main(void) { Daughter daughters[10]; // The main program sets the value of the // Counting semaphore to a negative number sem1.SetVal(-9); for( int i=0; i < 10; i++) daughters[i].Start(); // Now wait for a P to be able to exit sem1.P(); cout << "Main: Got a P" << endl; return 0; }