Question
In C! Implement a solution to the critical section problem with threads using semaphores . Make a counting thread which counts by 1 each time
In C!
Implement a solution to the critical section problem with threads using semaphores. Make a counting thread which counts by 1 each time it enters its critical section to 2,000,000. Each counts to 2,000,000 for a total of 6,000,000.
use seminit, semwait, and sempost.
Make comments indicating the following sections in your code:
entry section
critical section
exit section
remainder section
Expected output:
both threads need to report the number of updates done at the end of their remainder sections.
both threads need to report the current value of the shared variable counter at the end of their remainder sections.
thread1 needs to report the number of times it got the bonus at the end of its remainder sections.
Im thread1, I did 2000000 updates and I got the bonus for 18562 times, counter = 2106222 Im thread3, I did 2000000 updates, counter = 5573136 Im thread2, I did 2000000 updates, counter = 6000000 from parent counter = 6000000
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started