Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given the 5 data generators adapt the following code to meet requirments. Must use POSIX threads and semaphores to complete. It also must be written

Given the 5 data generators adapt the following code to meet requirments. Must use POSIX threads and semaphores to complete. It also must be written in c++

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 thread ihas n unprocessed numbers, data-generator thread i must contact the server thread n times. 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.

Here is the code that needs to be added to in order to meet the requirments.

#include #include #include #include #include

using namespace std;

int random(int max, int min){ int a; a = rand() % (max-min +1) + min; } void task1() { int data[10]; for(int i = 0; i<10; i++){ int b = random(100,199); while(1){ int found = 0; for (int j = 0; j

void task2() { int data[10]; for(int i = 0; i<10; i++){ int b = random(200,299); while(1){ int found = 0; for (int j = 0; j

void task3() { int data[10]; for(int i = 0; i<10; i++){ int b = random(300,399); while(1){ int found = 0; for (int j = 0; j

void task4() { int data[10]; for(int i = 0; i<10; i++){ int b = random(400,499); while(1){ int found = 0; for (int j = 0; j

void task5() { int data[10]; for(int i = 0; i<10; i++){ int b = random(500,599); while(1){ int found = 0; for (int j = 0; j

int main() { srand(time(NULL)); thread first(task1); thread second(task2); thread third(task3); thread fourth(task4); thread fifth(task5);

first.join(); second.join(); third.join(); fourth.join(); fifth.join();

cout << "task1 ,task2 and task3,tak4 and tak5 completed. "; return 0; }

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

Advances In Knowledge Discovery In Databases

Authors: Animesh Adhikari, Jhimli Adhikari

1st Edition

3319132121, 9783319132129

More Books

Students also viewed these Databases questions

Question

LO3 Discuss the steps of a typical selection process.

Answered: 1 week ago