Question: C language is the preferred choice of coding! PLEASE READ THOROUGHLY!!! Objective: In this assignment, you will be writing a multithreaded program that shares data

C language is the preferred choice of coding! PLEASE READ THOROUGHLY!!!

Objective:

In this assignment, you will be writing a multithreaded program that shares data between threads. Your actual program is meant to take in values, find its factors and display them. You will need to properly protect data that is shared between threads. You will be using mutex locks around critical sections to ensure your program works correctly and does not experience race conditions.

Details:

You will write the program to only use three threads; the main thread, a producer, and a consumer. The three threads will accomplish the following tasks:

Main Thread:

Create the producer and consumer threads

Send each number from the command line to the producer thread via a shared buffer.

This buffer only needs to be shared between the main thread and the producer.

Wait for each thread to complete before terminating the program

Producer Thread:

Wait for numbers to be added to the buffer shared with the main thread

Factor each number

Save numbers to a buffer shared between the producer and consumer threads

Consumer Thread:

Wait for factors to be added to the buffer shared with the producer thread

Display the factors

This program will use two sets of shared data, in the producer-consumer style. Both sets of data need to be protected using pthread_mutex_t variables. The only thread producing any output to the console should be the consumer thread. All other threads should perform their actions silently.

Output:

Here are several examples of what is expected when you run your program:

# ./assn3 Usage:./assn3 ...

# ./assn3 12 12: 2 2 3

# ./assn3 7 12 25 7: 7 12: 2 2 3 25: 5 5

# ./assn3 {32..48} 32: 2 2 2 2 2 33: 3 11 34: 2 17 35: 5 7 36: 2 2 3 3 37: 37 38: 2 19 39: 3 13 40: 2 2 2 5 41: 41 42: 2 3 7 43: 43 44: 2 2 11 45: 3 3 5 46: 2 23 47: 47 48: 2 2 2 2 3

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!