Categories: Uncategorized

Assignment 2 (50 points) Due Date: 8/5/2018 (11:59pm)

Assignment 2 (50 points) Due Date: 8/5/2018 (11:59pm) In this assignment, you are going to write a C program to utilize multi-threads, mutex lock, and semaphores for the producer and consumer problem. You will need to utilize your assignment 1 for your assignment 2. Define an integer buffer with the size of 32 and implement a circular queue data structure that is used by producers and a consumer. Next, you will need to initialize the mutex lock and semaphores. In this assignment, you will use two semaphores where one indicates a full queue and the other indicates an empty queue. The producer function is used to insert a random number between 0 and 10 to the queue. The consumer function is used to remove a number from the queue in a FIFO fashion. In addition, inside the loops of the producer and consumer functions, add a random delay between 0 and 2 seconds to simulate various lengths of processes. In addition, you are required to use 2 producers and 1 consumer for this assignment where 0 and 2 are producers and 1 is consumer (3 threads). Finally, your code should run forever. The expected results should look similar to the following Thread 2 – Produce 8 (1) Thread 2 – Produce 8 (2) Thread 2 – Produce 3 (3) Thread 2 – Produce 5 (4) Thread 1 – Consume 8 (3) Thread 0 – Produce 3 (4) Thread 1 – Consume 8 (3) Thread 0 – Produce 8 (4) Thread 0 – Produce 4 (5) Thread 2 – Produce 8 (6) Thread 1 – Consume 3 (5) Thread 0 – Produce 4 (6) Thread 2 – Produce 4 (7) Thread 0 – Produce 3 (8) Thread 0 – Produce 2 (9) Thread 0 – Produce 2 (10) Thread 0 – Produce 8 (11) Thread 1 – Consume 5 (10) Thread 0 – Produce 1 (11) Thread 2 – Produce 5 (12) Thread 0 – Produce 2 (13) Thread 0 – Produce 2 (14) Thread 0 – Produce 9 (15) Thread 0 – Produce 9 (16) Thread 1 – Consume 3 (15) Thread 2 – Produce 7 (16) Thread 0 – Produce 1 (17) Thread 1 – Consume 8 (16)

Thread 0 – Produce 5 (17) Thread 2 – Produce 6 (18) Thread 1 – Consume 4 (17) Thread 0 – Produce 2 (18) Thread 2 – Produce 0 (19) Thread 2 – Produce 0 (20) Thread 2 – Produce 2 (21) Thread 2 – Produce 6 (22) Thread 2 – Produce 9 (23) Thread 2 – Produce 0 (24) Thread 2 – Produce 3 (25) Thread 0 – Produce 7 (26) Thread 1 – Consume 8 (25) Thread 2 – Produce 8 (26) Thread 0 – Produce 9 (27) Thread 2 – Produce 6 (28) Thread 0 – Produce 8 (29) Thread 1 – Consume 4 (28) Thread 2 – Produce 2 (29) Thread 0 – Produce 1 (30) Thread 1 – Consume 4 (29) Thread 0 – Produce 2 (30) Thread 0 – Produce 2 (31) Thread 2 – Produce 4 (32) Thread 1 – Consume 3 (31) Thread 0 – Produce 3 (32) BUFFER is FULL … Thread 1 – Consume 2 (31) Thread 0 – Produce 4 (32) Thread 1 – Consume 2 (31) Thread 0 – Produce 0 (32) Thread 1 – Consume 8 (31) Thread 2 – Produce 0 (32) BUFFER is FULL … BUFFER is FULL … BUFFER is FULL … BUFFER is FULL … BUFFER is FULL … Thread 1 – Consume 1 (31) Thread 0 – Produce 2 (32) BUFFER is FULL … Thread 1 – Consume 5 (31) Thread 2 – Produce 0 (32) BUFFER is FULL … BUFFER is FULL … BUFFER is FULL … BUFFER is FULL … BUFFER is FULL … where the number is the thread identifier, the second number is the random number inserted to or removed from the queue, and the third number is the queue index. Also, print out a message when the buffer is full or empty.

Don't use plagiarized sources. Get Your Custom Essay on
Assignment 2 (50 points) Due Date: 8/5/2018 (11:59pm)
This is a Snippet Preview, get a Complete Solution Here
Order Essay

All programs must be run under the department’s Unix server. To compile your code in Unix, you need to include pthread as follows >> gcc Assign2.c –pthread Submission Submit your code to blackboard.

Phyllis Mugure

Recent Posts

Introduction to psychology | Assignments Market

ASSIGNMENT 08 S01 Introduction to Psychology I Directions: Be sure to save an electronic copy…

4 years ago

Education | Assignments Market

Include a comprehensive, thoughtful and critical analysis to the arguments and perspectives of the readings…

4 years ago

Session 2 Discussion | Assignments Market

Discussion Prompt: Plagiarism As a writer, one of the gravest errors to make is to…

4 years ago

CJL Writing Questions | Assignments Market

Question 1: Write a Hypothetical. Write a legal memorandum analyzing what happened in the following…

4 years ago

short HW all the questions below | Assignments Market

You work at Happy Joe's family restaurant and want to see if customer meal satisfaction…

4 years ago

321 solve … | Assignments Market

The Assignment must be submitted on Blackboard (WORD format only) via allocated folder. Assignments submitted…

4 years ago