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, 23.06.2019 03:00
Your business be in google top rank.more the rank more the business leads.for best seo and digital marketing services be confident to contact you can get best seo solutions by assistance experts provide digital marketing, website development, seo expert services and social media internet seo expert services your branding solutions. seo expert services ,best seo expert services,online seo expert services,
Answers: 3
question
Computers and Technology, 24.06.2019 09:50
Suppose you are an ad-serving company and you maintain a log of cookie data for ads you serve to the web pages for a particular vendor (say amazon). a. how can you use this data to determine which are the best ads? b. how can you use this data to determine which are the best ad formats? c. how could you records of past ads and ad clicks to determine which ads to send to a given ip address? d. how could you use this data to determine how well the technique you used in your answer to part c was working? e. how could you use this data to determine that a given ip address is used by more than one person? f. how does having this data give you a competitive advantage vis-à-vis other ad-serving companies?
Answers: 2
question
Computers and Technology, 24.06.2019 11:30
Convert 11001110(acdd notation) into decimal
Answers: 2
question
Computers and Technology, 24.06.2019 20:00
Which element will you include to present numerical on a slide? a: graph b: text c: flowchart d: shapes
Answers: 1
You know the right answer?
The goal of this assignment is to write a multithreaded program that explores synchronization challe...
Questions
question
English, 04.06.2021 14:00
question
Mathematics, 04.06.2021 14:00
question
Mathematics, 04.06.2021 14:00
question
Biology, 04.06.2021 14:00
Questions on the website: 13722367