Question: Design and implement a program in C++ and you must use POSIX threads and semaphores to complete this project. This project creates a system to

Design and implement a program in C++ and you must use POSIX threads and semaphores to complete this project.

This project creates a system to simulate a data center. The following rules apply:

1) 5 data-generator threads are created in the main thread at the start of simulation. Each data-generator thread has a unique index ranging from 1 to 5. Each data-generator thread generates 10 random numbers (no duplicate numbers) with the following requirement:

a) The random numbers generated by data-generator thread 1 are ranging from 100 to 199.

b) The random numbers generated by data-generator thread 2 are ranging from 200 to 299.

c) The random numbers generated by data-generator thread 3 are ranging from 300 to 399.

d) The random numbers generated by data-generator thread 4 are ranging from 400 to 499.

e) The random numbers generated by data-generator thread 5 are ranging from 500 to 599.

2) 2 data-server threads are created in the main thread at the start of simulation. Each data-server thread has a unique index, ranging from 1 to 2.

3) Every number datum has to be processed by a data-server thread. A total of 50 number-data are processed by two data-server threads.

4) If a data-generator thread has unprocessed data, the data-generator thread contacts a data server. A data-generator thread only sends one number datum each time. If data-generator threadihasnunprocessed numbers, data-generator threadimust contact the server threadntimes. Each number can processed by the same or different servers. If both data-server threads are busy (i.e., processing data from another data-generator thread), the data-generator thread is waiting for the availability of a data server based on the FIFO order. If both data servers are available, simply choose one server to handle the number datum. Each data-server can only handle one number datum one time.

5)Server Connection.A data-generator thread contacts a data-server thread with the following handshaking procedure:

a) A data-generator thread connects to a data-server thread. (You must print out this activity in the data-generator thread, e.g., Data-generator thread 1 connects to data-server thread 2.)

b) The data-server thread accepts the connection from the data-generator thread. (You must print out this activity in the data-server thread, e.g., Data-server thread 2 accepts the connection from data-generator thread 1.)

c) The data-server thread sends a connection confirmation to the data-generator thread. (You must print out this activity in the data-server thread, e.g., Data-server thread 2 sends the connection confirmation to data-generator thread 1.)

d) The data-generator thread receives the connection confirmation from the data-server thread. (You must print out this activity in the data-generator thread, e.g., Data-generator thread 1 receives the connection confirmation from data-server thread 2.)

6) A data-server thread sleeps random time (50-200 ms) to simulate the procedure of handling a number datum.

7)Server Completion.A data-server thread contacts a data-generator thread with the following handshaking:

a) The data-server thread sends the completion message to the data-generator thread. (You must print out this activity in the data-server thread, e.g., Data-server thread 2 completes processing number datum 135 and notifies data-generator thread 1.)

b) The data-generator thread receives the notification. (You must print out this activity in the data-generator thread, i.e., Data-generator thread 1 acknowledges the completion of the number datum 135 from data-server thread 2).

8) Repeat the steps 4-7 if any data are not processed. In the server connection (Step 5), you must print out the indices of the data-generator thread and the data-server thread. In the server completion (Step 7), you must print out the number datum in addition to the indices of the data-generator thread and the data-server thread.

9) In the end of the simulation, a report is printed by each data-generator thread. See the following sample. Reports from different data-generator threads should not be interleaving.

------Report Of Data-generator Thread 1------

135 processed by data-server 2

142 processed by data-server 1

162 processed by data-server 1

115 processed by data-server 2

122 processed by data-server 1

152 processed by data-server 1

112 processed by data-server 1

134 processed by data-server 2

189 processed by data-server 1

184 processed by data-server 1

------End of Report of Data-generator Thread 1-----

Please complete all requirements

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!