Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C language is the preferred choice of coding Please show an image that displays the results when you run the program. Objective: In this assignment,

C language is the preferred choice of coding

Please show an image that displays the results when you run the program.

Objective:

In this assignment, you will be writing a multithreaded program that shares data between threads. 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:

The previous program could possibly use too many threads and we need to fix that problem. 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

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_2

Step: 3

blur-text-image_3

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

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

10th Edition

0137916787, 978-0137916788

More Books

Students also viewed these Databases questions

Question

Write a note on job design.

Answered: 1 week ago

Question

Compute the derivative of f(x)cos(-4/5x)

Answered: 1 week ago

Question

Discuss the process involved in selection.

Answered: 1 week ago

Question

Differentiate tan(7x+9x-2.5)

Answered: 1 week ago