semaphore A = 1;
semaphore B = 1; semaphore C = 3; void thread1() { while (1) { wait( A ); wait( B ); wait( C ); x = x - 10; y = y + 10; signal( A ); signal( B ); signal( C ); } } |
void thread2()
{ wait( B ); wait( A ); wait( C ); x = x + 10; y = y - 10; signal( A ); signal( B ); signal( C ); } |
....
// Create a thread for every request ssock = accept( msock, &sin, alen ); thr_create( .. , processRequest, ssock ); close( ssock ); .... |