Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Expected Output: Here are several examples of what is expected when you run your program: # ./assn3 Usage:./assn3 ... # ./assn3 12 12: 2 2

Expected 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

C language is the preferred choice of coding

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:

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.

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 A Beginners Guide

Authors: Andy Oppel

1st Edition

007160846X, 978-0071608466

More Books

Students also viewed these Databases questions

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago