Question: COMPUTER SCIENCE OPERATING SYSTEMS CODE HELP PLEASE #include #include #include #include #include #include #define NUM_THREADS 20 #define HALF_SECOND 10e5 //Global variable enum {EMPTY, MEN_ONLY, WOMEN_ONLY}

COMPUTER SCIENCE OPERATING SYSTEMS CODE HELP PLEASE

COMPUTER SCIENCE OPERATING SYSTEMS CODE HELP PLEASE #include #include #include #include #include

#include  #include  #include  #include  #include  #include  #define NUM_THREADS 20 #define HALF_SECOND 10e5 //Global variable enum {EMPTY, MEN_ONLY, WOMEN_ONLY} bathroom = EMPTY; /* a thread representing a man */ void *man(void *args){ //man_wants_to_enter printf("Man %u is using the restroom. ", pthread_self()); usleep(HALF_SECOND); //Put thread to sleep for 1/2 second //man_leaves pthread_exit(0); } /* a thread representing a woman */ void *woman(void *args){ //woman_wants_to_enter printf("Woman %u is using the restroom. ", pthread_self()); usleep(HALF_SECOND); //Put thread to sleep for 1/2 second //woman_leaves pthread_exit(0); } int main(int argc, char *argv[]){ int threadTypes[NUM_THREADS], i, j, temp; pthread_t tids[NUM_THREADS]; //0 represents a woman thread, 1 a man thread for (i = 0; i = 0; i--){ //generate a random number [0, n-1] j = rand() % (i+1); //swap the last element with element at random index temp = threadTypes[i]; threadTypes[i] = threadTypes[j]; threadTypes[j] = temp; } /* Create some men and women threads. Due to shuffling, man and woman threads are created randomly. */ for (i = 0; i   4. Suppose that a university wants to show off how politically correct it is by applying the U.S. Supreme Courts "Separate but equal is inherently unequal doctrine to gender as well as race, ending its long- standing practice of gender-segregated bathrooms on campus. However, as a concession to tradition, it decrees that when a woman is in a bathroom, other women may enter, but no men, and vice versa. For example, if a woman is currently using the restroom and another woman wants to use the restroom, the second woman is allowed to enter. However, if a man wants to use the restroom, he must wait. A sign with a sliding marker on the door of each bathroom indicates which of three possible states it is currently in: Empty Women present Men present In C code using whatever constructs you like (mutexes, condition variables, semaphores, etc.), write the following procedures woman wants to.enter man wants to enter woman leaves man leaves

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!