#include #include #include const int LOOPS = 10; Mutex mutex1, mutex2; class Daughter :public Thread { public: Daughter(){} protected: void Run(void) { for(int i=0; i < LOOPS; i++ ) { cout << "Daughter trying lock" << endl; mutex1.P(); cout << "This is the daughter :" << endl; mutex2.V(); cout << "Daughter removed lock :" << endl; } } }; class Mother : public Thread { public: Mother() { } protected: void Run(void) { Daughter daughter; daughter.Start(); for( int i=0; i < LOOPS; i++) { cout << "Mother trying lock" << endl; mutex2.P(); cout << "This is the mother :"<< endl; mutex1.V(); cout << "Mother just unlocked :"<< endl; } } }; int main(void) { int retval; retval = mutex2.P(); Mother mother; mother.Start(); Thread::Join(&mother); return 0; }