Question

In: Computer Science

A snooker club can be used by players of both sex i.e. male and female, but...

A snooker club can be used by players of both sex i.e. male and female, but not both at the same time. If a boy is in the club, other boys may enter, but any girl wishing to play snooker should wait until all boys leave and club become empty. Similarly, if a girl is in the club, other girls may enter, but any boy wishing to play should wait till the club becomes empty. Implement a solution to this problem using SEMAPHORES. At maximum only 6 boys or 6 girls can enter the club and play snooker as there are only 3 tables available in the club.

Solutions

Expert Solution

Male Snooker:

do{
      
        // Male snooker want to enter into club so wait on m_snook
        // bcoz we are changing common variable n_m_snook(no of male snooker)
        wait(m_snook);
      
        //incrementing no of male snookers
        n_m_snook++;
      
        //blocking the female snookers if he is the first male snooker to enter into club
        if(n_m_snook==1)
        {
            wait(f_snook);
        }
      
      
        //blocking the male snooker if n_m_snook>6
        //since we can allow only 6 snookers
        if(n_m_snook>6)
        {
            //blocking male snooker until one male snooker left the club
           while(n_m_snook>6)
           {
               wait(m_snook);
           }
        }
      
        //now the male snooker entered into club
        //now we can allow other male snookers
        //so signal on m_snoock
        signal(m_snook);
      
        //one male snooker want to leave the club and change the n_m_snook
        //Therefore wait on m_snook
        wait(m_snook);
      
        //decrement the n_m_snook value
        n_m_snook--;
      
        //if he is the last male snooker to leave the club
        //then we can allow female snookers to the club
        if(n_m_snook==0)
        {
            signal(f_snook);
        }
      
        //male snooker changed n_m_snook value and left
        signal(m_snook);
      
      
    }while(true);

Female Snooker:

do{
      
        // female snooker want to enter into club so wait on f_snook
        // bcoz we are changing common variable n_f_snook(no of male snooker)
        wait(f_snook);
      
        //incrementing no of female snookers
        n_f_snook++;
      
        //blocking the male snookers if she is the first female snooker to enter into club
        if(n_f_snook==1)
        {
            wait(m_snook);
        }
      
      
        //blocking the female snooker if n_f_snook>6
        //since we can allow only 6 snookers
        if(n_f_snook>6)
        {
            //blocking female snooker until one female snooker left the club
           while(n_f_snook>6)
           {
               wait(f_snook);
           }
        }
      
        //now the female snooker entered into club
        //now we can allow other female snookers
        //so signal on f_snoock
        signal(f_snook);
      
        //one female snooker want to leave the club and change the n_f_snook
        //Therefore wait on f_snook
        wait(f_snook);
      
        //decrement the n_f_snook value
        n_f_snook--;
      
        //if she is the last female snooker to leave the club
        //then we can allow male snookers to the club
        if(n_f_snook==0)
        {
            signal(m_snook);
        }
      
        //female snooker changed n_f_snook value and left
        signal(f_snook);
      
      
    }while(true);

semaphores used: m_snook, f_snook

common variables used: n_m_snook, n_f_snook

wait()--decrements the value by 1(makes 0 )

signal()--increments the value by 1


Related Solutions

1. Define primary sex organs in a male and a female. Secondary sex organs in a...
1. Define primary sex organs in a male and a female. Secondary sex organs in a male and a female. 2. Define secondary sex characteristics.
List the normal pair of sex chromosomes, and possible sex chromosome aneuploidy for male and female,...
List the normal pair of sex chromosomes, and possible sex chromosome aneuploidy for male and female, respectively. And then briefly explain the possible mechanism of XY girls and XX boys.
In a club with 8 male and 10 female​ members, how many 4​-member committees can be...
In a club with 8 male and 10 female​ members, how many 4​-member committees can be chosen that have ​(a) at least 3 ​women? ​(b) no more than 2 ​men?
Hermaphrodites are individual organisms containing both male and female sex organs. Discuss how sexual selection might...
Hermaphrodites are individual organisms containing both male and female sex organs. Discuss how sexual selection might operate on hermaphrodites, and explain which different aspects of sexual selection are likely to be stronger or weaker in hermaphrodites than in separate-sexed organisms.
A species of daisy has hermaphroditic flowers (i.e., each flower produces both male and female gametes)....
A species of daisy has hermaphroditic flowers (i.e., each flower produces both male and female gametes). Researchers genotyped 1,000 individuals at a single nucleotide polymorphism (SNP) in three populations. The numbers of each genotype in each population were: Genotype Population 1 Population 2 Population 3 TT 90 200 50 TC 420 200 500 CC 490 600 450 a. For each population, calculate the allele frequencies and determine whether the population is currently at Hardy-Weinberg equilibrium b. For populations not at...
Biologically what is the difference between male and female? Is sex a static state for all...
Biologically what is the difference between male and female? Is sex a static state for all organisms give examples for your answer.
Male and female Rats (sex) were provided with either food of type 1 or food of...
Male and female Rats (sex) were provided with either food of type 1 or food of type 2 (food) and the subsequent consumption (cons) rate was measured. Was there a difference in the consumption rate of rats based on the food type and their sex? Use the data provided on Blackboard (‘RatsFood.xlsx’to complete the analysis as asked below). For this question – the data are indeed normally distributed (no need to check)… What are the null and alternative hypotheses? What...
In birds the male has two identical Z sex chromosomes (males are ZZ), whereas the female...
In birds the male has two identical Z sex chromosomes (males are ZZ), whereas the female has one Z as well as a nearly blank chromosome, designated W (females are ZW). In parakeets two genes control feather color. The presence of the dominant Y allele at a Z-linked gene results in the production of a yellow pigment. The dominant B allele at an autosomal gene controls melanin production. When dominant alleles are present for both genes, the feathers are green....
Mitchell and Cameron have two adopted children. We are interested in the biological sex (Male/Female) of...
Mitchell and Cameron have two adopted children. We are interested in the biological sex (Male/Female) of their children. (a)[3 pts] Give the sample space for thesex of their two children.1 full point out of the 3will be for using the correct format. (b)[2 pts] What is the probability that both children are girls, given that the first child is a girl? You do not have to show a lot of mathematical work for this, but the more work you show,...
Independent random samples were taken of male and female members of University Entrepreneurship Club. These members...
Independent random samples were taken of male and female members of University Entrepreneurship Club. These members were considering starting a business. Of 500 members, 150 actually started a business venture. Estimate the value of the population proportion. (Round your answers to 3 decimal places.) Develop a 99% confidence interval for the population proportion.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT