Question: can you please help with this program at the bottom is what i have so far, Assignment Overview: For this assignment, you are to design

 can you please help with this program at the bottom is what i have so far, Assignment Overview: For this assignment, you are to design and implement a C/C++ program that uses POSIX threads and semaphores to correctly manage a bounded buffer and solve the Producer/Consumer problem. This assignment is worth 40 points, and must be completed no later than 11:59 PM on Thursday, March 17. Assignment Specifications: 1) The program will create N producer threads and one consumer thread which share access to a bounded buffer. The number of producers (the value of N) will be available to the program as the first command-line argument, will not exceed 10, and will default to 1. 2) The buffer will be circular and will consist of 20 records, where each record contains a thread ID number and an integer sequence number. 3) Each producer will generate the first 100 integers, starting at one. For each of those integer values, the producer will build a record and insert it into the circular buffer. The record will contain the producer's thread ID and the integer value (the sequence number). 4) The consumer will retrieve each record from the buffer and print its contents on the standard output stream in a readable format. 5) The critical sections of the producer(s) and consumer will be kept as small as possible. 6) The program will function correctly, even though the producer(s) and/or consumer are interrupted inside and/or outside their critical sections. 7) The program will use POSIX semaphores to coordinate the producers and consumers, as well as to guard critical sections. 8) The program will perform appropriate error-handling. Assignment Deliverables: The deliverables for this assignment include the following files: proj06.makefile -- the make file which produces "proj06" proj06.*.c -- the C/C++ source code file(s) for your solution proj06.*.h -- the interface file(s) for your solution Be sure to use the specified file names, and to submit your files for grading via the "handin" program. Assignment Notes: Command-line arguments are arrays of type "char" in C/C++; the function "atoi" can be used to convert a character string into an integer value. Your program should use function "sched_yield" and random numbers to simulate interruptions both inside and outside a process' critical section. A process should be interrupted approximately 12.5% of the time inside its critical section and approximately 25% of the time outside its critical section. Be sure to use "-lpthread" when you link your program. 

i think i have the basic idea but i cant figure some things out, Thank you

#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std;

// globals are bad, ok? struct record{ int thread_id; int seq_num; }; vector buffer(20);

const int sizeofbuffer = 20;

semaphore s = 1, n=0, e = sizeofbuffer; int in = 0; int out =0;

void *producer(void *number){

cout<<"number:" << number<

void *consumer(void* number){

int num = number * 100; for(int j=0; j < num;j++){ sem_wait(n); sem_wait(s); cout << "Thread ID : " << my_data->thread_id<seq_num << endl; sem_signal(s); sem_signal(e); } pthread_exit(NULL); }

int main(int argc, char *argv[]) { cout<<""<< argv[1]<

int num = atoi(argv[1]); pthread_t mythread[num]; struct record td[num]; int i; int rc=1; for (i=0; i

if (pthread_create( &mythread[i], NULL,producer,NULL)){ cout << "Error:unable to create thread"<

if (pthread_create( &mythread[i], NULL,consumer(),&num)) { printf( "*** Error creating thread *** " ); exit( -1 ); } pthread_exit(NULL); return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!