Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Goal Practice threads synchronization and cooperatively execute some tasks, while solving some related issues like deadlocks and races. Reference: the textbook chapter 4 to 6
Goal
Practice threads synchronization and cooperatively execute some tasks, while solving some
related issues like deadlocks and races.
Reference: the textbook chapter to
Description
Please read the complete assignment document carefully before starting.
Write a program C Pthread is suggested but you can also use java or windows if you prefer
which will have to create threads. These threads share some resources and cooperatively
execute some tasks.
The program should have integer variables shared among all threads, int: and turn.
These variables should be the only global variables. Any other needed variables should be
declared as a local variable to each functionthread The main thread should ask the user to
enter a zero or positive values: for variables and turn use scanf turn can take only
values from to Then the main thread should create the theads and
Each thread will run on a different function with the prototype: void thrn where is the
thread number to
Once started, the thread scheduling should work as follows:
a The threads will run in round robin RR
b The value of the variable turn define which thread will run first eg if turn then
Th Th Th Th dots
c The value of the variable a define the number of threads RR repetition before
terminating eg if and turn then
d Only thread is allowed to execute its critical section CS at a time. Eg when Th
is executing, all other threads should be in a busy wait BW
e When an executing thread exit its CS it must set the value of variable turn to the
next Thread to execute.
f Then main thread or the parent thread should wait join after all children
threads to terminate before continuing the execution of its remaining section to
produce some useful data then terminates.
Each thread task is as follows:
a Th: calculates print the Thead # and value for an a repetition
b Th: calculates print the Thead # and value for an a repetition
c Th: calculates print the Thead # and value for an a repetition
d Th: calculates print the Thead # and value for an a repetition
Solve everything thank you
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