Consumer Problem With Inter Thread Communication

READ PROPERLY AND SHOW THE OUTPUT SAME AS THE EXAMPLE OUTPUT. PLEASE DO NOT COPY AND PASTE FROM OTHER ANSWER THOSE ARE WRONG*****

Solve the producer and consumer problem with inter thread communication (join(), wait(),
sleep() etc.) modifying the given C code. Consumer Problem With Inter Thread Communication

 

ORDER A PLAGIARISM-FREE PAPER HERE

Half of the code is already given you just need to modify where it is required. The output should be same as the sample. Please do not copy from other answers of this question. Do not try if you don’t know how to solve or else you won’t get any upvote.

The answer must be in C language

#include <pthread.h>
#include <stdio.h>
#include <string.h>
#define MAX 10 //producers and consumers can produce and consume upto MAX
#define BUFLEN 6
#define NUMTHREAD 2 /* number of threads */
void * consumer(int *id);
void * producer(int *id);

char buffer[BUFLEN];
char source[BUFLEN]; //from this array producer will store it’s production into buffer
int pCount = 0;
int cCount = 0;
int buflen;
//initializing pthread mutex and condition variables
pthread_mutex_t count_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t nonEmpty = PTHREAD_COND_INITIALIZER;
pthread_cond_t full = PTHREAD_COND_INITIALIZER;
int thread_id[NUMTHREAD] = {0,1};
int i = 0;
int j = 0;
main() Consumer Problem With Inter Thread Communication
{
int i;
/* define the type to be pthread */
pthread_t thread[NUMTHREAD];
strcpy(source,”abcdef”);
buflen = strlen(source);
/* create 2 threads*/
/* create one consumer and one producer */
/* define the properties of multi threads for both threads */
//Write Code Here

}

void * producer(int *id)
{
/*
1. Producer stores the values in the buffer (Here copies values from source[] to buffer[]).
2. Use mutex and thread communication (wait(), sleep() etc.) for critical section.
3. Print which producer is storing which values using which thread inside the critical
section.
4. Producer can produce upto MAX
*/
//Write code here
}

void * consumer(int *id) Consumer Problem With Inter Thread Communication
{
/*
1. Consumer takes out the value from the buffer and makes it empty.
2. Use mutex and thread communication (wait(), sleep() etc.) for critical section
3. Print which consumer is taking which values using which thread inside the critical
section.
4. Consumer can consume upto MAX
*/
//Write code here Consumer Problem With Inter Thread Communication 

× How can I help you?