Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Design and implement a solution for Producer-Consumer Problem using Pthreads library in Linux Virtual Machine. /* buffer.h*/ typedef int buffer_item; #define BUFFER_SIZE 5 int insert_item(buffer_item

Design and implement a solution for Producer-Consumer Problem using Pthreads library in Linux Virtual Machine.

image text in transcribed

/* buffer.h*/

typedef int buffer_item;

#define BUFFER_SIZE 5

int insert_item(buffer_item item);

int remove_item(buffer_item *item);

//Code to be used for this.

#include "buffer.h"

#include

#include

#include

#include

buffer_item buffer[BUFFER_SIZE];

void *producer(void *param);

void *consumer(void *param);

int insert_item(buffer_item item)

{

/* Acquire Empty Semaphore */

/* Acquire mutex lock to protect buffer */

/* Insert item into buffer */

/* Release mutex lock and full semaphore */

return 0;

}

int remove_item(buffer_item *item)

{

/* Acquire Full Semaphore */

/* Acquire mutex lock to protect buffer */

/* remove an object from buffer placing it in item */

/* Release mutex lock and empty semaphore */

return 0;

}

int main(int argc, char *argv[])

{

/* Get command line arguments argv[1],argv[2],argv[3] */

/* Initialize buffer related synchronization tools */

/* Create producer threads based on the command line input */

/* Create consumer threads based on the command line input */

/* Sleep for user specified time based on the command line input */

return 0;

}

void *producer(void *param)

{

/* producer thread that calls insert_item() */

}

void *consumer(void *param)

{

/* consumer thread that calls remove_item() */

}

Download buffer.h and the incomplete version of hw3.c from iCollege Read through Programming Project 3 of Chapter 5 (Producer-Consumer Problem) in the textbook. Follow the suggestion in the textbook to complete the C program using Pthreads. Do NOT solve the problem using Windows API. In addition to the requirement in the textbook, print a message every time an item is produced or consumed in your producer and consumer threads. The message should also include the thread ID of the producer or consumer. To get a thread's ID, you may call pthread_self() function and convert the result into an integer. For example, you can use printf("Consumer %u consumed %d ",(unsigned int)pthread-self(), consumed-number); for the consumer. You can use a similar code for the producer. . * . Compile the C source file using gcc-pthread -o hw3 hw3.c . Use ./hw3 sleep time>

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

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions

Question

Define organisational structure

Answered: 1 week ago

Question

Define line and staff authority

Answered: 1 week ago

Question

Define the process of communication

Answered: 1 week ago

Question

Explain the importance of effective communication

Answered: 1 week ago

Question

* What is the importance of soil testing in civil engineering?

Answered: 1 week ago

Question

7. Where Do We Begin?

Answered: 1 week ago

Question

a. What is the purpose of the team?

Answered: 1 week ago

Question

b. What are its goals and objectives?

Answered: 1 week ago