Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer the following questions thoroughly. Do not copy and paste other answers online. Thank you. Consider the following program which we will call PlayHT:

Please answer the following questions thoroughly. Do not copy and paste other answers online. Thank you.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Consider the following program which we will call PlayHT: Change the program as follows: a. Instead of using two threads (for Players A and B), make the program work with more threads. Use the symbolic constant value: NUM_PLAYERS to define this value. You must use arrays to keep track of the different threads. b. The program plays one instance of the game; that is, it loops until a winner is found. Instead of terminating at this point, modify the program to play additional games using the same threads. Use the constant value: NGAMES to specify how many games are to be played. Between each game the threads are to resynchronize and re-initialize their own relevant variables. Your modified program must issue a message after the resynchronization has occurred for each game; for example: Threads resynchronized after game: nnn Display statistics that show how many games were won by each thread; see sample output below. Study the man pages for pthreads. Solve this problem without using the pthread_barrierfunctions. Also, it is NOT acceptable to use busy waiting or delay routines such as sleep. Note: compile the code as follows: g++3td=c++110 pHT -pthread PlayHT.cpp, where pHI is the executable and PlayHT.cpp is the source file. In addition, your code must ensure that all shared variables are updated in a mutually exclusive manner. Turn in a listing of your code and output that shows it works correctly with the following parameter values: NUM_PLAYERS equal to 8 NGAMES equal to 1000 . Only turn in 2 pages of execution output that show the start and end of the execution; the summary statistics must be displayed. On your listing, highlight the changes you made to the above program. All threads must exit successfully and the All Games Over message must be issued by main. Output from execution of above code: Player: 1 Starting game: 1 Thread 1 TTHTT Thread 1 THTTH Thread 1 HTTHT Thread 1 TTTHT Thread 1 TTTHir Thread 1 TTHTr Player: 2 starting game: 1 Thread 2 TTHTr Thread 2 HHHHH Thread 2 wins game: 1 Thread 1 TTHTH Thread 1 loses game: 2 \{note: this should state game 1\} All Games over Number of wins by player 1: 0 Number of wing by player 2:1 Partial output that demonstrates solution with 4 players and 500 games: Thread 4 wing game: 499 Thread 2 HHHTH Thread 2 loges game: 499 Thread 1 TITTH Thread 1 loseg game: 499 Player: 3 Starting game: 499 Thread 3 HITHH Thread 3 loses game: 499 Threadis resynchronized after game: 499 Player: 1 Starting game: 500 Player: 3 Starting game: 500 Inread 3 ITTHH Thread 3 HHTHH Thread 1 TITHH Thread 1 ITTTH Thread 1 HHTHH Thread 3 TTHTH Player: 2 Starting game: 500 Thread 3 TTHHT Thread 3 HTHHI Thread 1 HHTTH Thread 2 HTHHH Thread 1 HITTH Thread 3 THHTT Thread 3 HITHH Thread 3 TTHTH Thread 2 HHTTH Player: 4 Starting game: 500 Thread 2 ITTHT Thread 3 HHTTT Thread 3 THHHH Thread 1 THTHH Thread 1 TITHH Thread 2 HTTHH Thread 1 THTTH Thread 3 ITTTH Thread 2 HHHHH Thread 3 HTTHT Thread 3 loses game: 500 Thread 4 TTHHH Thread 2 wins game: 500 Thread 4 loses game: 500 Thread 1 THHTT Thread 1 loses game: 500 Threads resynchronized after game: 500 A11 Games Over Number of wins by player 1: 123 Number of wins by player 2: 99 Numier of wing by player 3: 155 Number of wing by player 4:123

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine Ricardo

2nd Edition

1449606008, 978-1449606008

More Books

Students also viewed these Databases questions

Question

=+professionalism and competency in handling global HR issues?

Answered: 1 week ago