Last edited on
First glance, the call of pthread_join could get wrong since the tid array's assign got wrong at #143 and #147.
For the use of semaphore, several comments:

1, what handling should be done when a thread is unlocked from sem_wait(&women or man_queue). I recond the man should go into restroon and the related counters should be changed.
2, what handling should be done when a man or women goes into the restroom? I recon the sem_post should be sent to wating queue to tell other bodies coming in.
3, when a men or women exiting, in man_leave or women_leave, the handling like #63 and #64 could be better done by women or men themselves.
4, why sem_wait(bath_door) even when they leave.
If a bathroom administrator is added, I guess one mutex is enough to fix this.
Topic archived. No new replies allowed.