Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

2. (16 points) Suppose we can have at most five threads in the critical section

ID: 3698786 • Letter: 2

Question

2. (16 points) Suppose we can have at most five threads in the critical section at any one time. Complete the following Go program so that it ensures that there are at most five threads (in this case, goroutines) in the critical section at once. Specifically, fill in the global shared data section in the main function, the entry and exit sections in the work function, and the parameter list for the work function. Do not use busy waiting. 1 var done= make (chan int) 2 var limit 100 4 func vor( 6 I/ Kentry 'section> ) t es like will neve te >S 10 11 /

Explanation / Answer

func main(){

                        var count = 5

                        // for loop goes here

}

func work {

            // entry

            P(count);

                        if not limit then {

                                    V(count);

                                    P(waitforlimit);

                        }

           

            //CS

           

           

            // exit

            P(count);

                        if limit{

                        V(waitforlimit);

        V(count);

                        };

           

            // if condition goes here

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote