subject

The goal of this assignment is to write a multithreaded program that explores synchronization challenge. For this part, assume that, we have a shared variable NextID. This is initialized to 1 at the beginning.
Now create 5 threads in your program and assign ID 1, 2, 3, 4, 5 to them respectively. You can pass the ID as a parameter when you create the threads.
Each of the threads will try to access the variable "NextID".
Whenever a thread acquires the variable, it checks whether the NextId is equal to its own Id or not.
If it is not equal, it will output "Not My Turn!", then print its threadId, and then release the variable.
If it is equal, the thread will print ""My turn!", then print its threadId, increase the NextId by 1, and then release the variable. However, after increasing NextID by 1, the thread will check if the value is 6 or not. If it is 6, it will reset it to 1 before releasing the variable.
The program should execute until each thread prints "Mu Turn!" 20 times. Once a thread prints for 20 times, it terminates.
Count the number of times each thread prints "Not my Turn!" and include that in the report.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 09:00
What is one way in which tablets differ from laptops and notebooks? tablets are designed for touch-based interaction. tablets are designed to be used as desktops. tablets are designed for input via a keyboard and mouse. tablets are designed to be larger than laptops.
Answers: 1
question
Computers and Technology, 22.06.2019 23:30
Creating "smart interfaces" in all sectors of industry, government, and the public arena is one of the fastest growing hct areas. these interfaces model, interpret, and analyze such human characteristics as speech, gesture, and vision. the field of biometrics, in which humans authenticate themselves to machines, is an area of considerable interest to hct practitioners. fingerprint scans are one of the most frequently used biometric options, and this article, biometric student identification: practical solutions for accountability & security in schools, makes a case for the implementation of fingerprint scans in schools. critique the article, and answer the following questions: according to the author, what are the main benefits of adopting fingerprint scans in schools for student identification? according to the author, what are the main drawbacks of adopting fingerprint scans in schools for student identification? do you agree with the author's assessment of the pl
Answers: 2
question
Computers and Technology, 23.06.2019 00:30
Which of the following would you find on a network
Answers: 3
question
Computers and Technology, 23.06.2019 03:30
How can you repin an image on your pinterest pin board a. click on the "repin" button b. click on the "add pin" button c. click on the "upload a pin" button d. click on the "save pin" button.
Answers: 2
You know the right answer?
The goal of this assignment is to write a multithreaded program that explores synchronization challe...
Questions
question
Mathematics, 24.03.2020 01:27
question
Mathematics, 24.03.2020 01:27
question
Mathematics, 24.03.2020 01:27
Questions on the website: 13722367