Question: Plug in code for code block #1-#7 in c programming language. // This macro defines how many units of data will be generated in total,
Plug in code for code block #1-#7 in c programming language.






// This macro defines how many units of data will be generated in total, // For simplicity, we use an integer to represent one unit of data, // therefore, this project actuall will generate at most 10 integers #de fine MAX 10 // We need the mutex to make sure that every time only one thread access the buffer // , could be the consumer thread or the producer thread. pthread mutex t the_mutex; // A blocked thread waits for the "traffic lights" before it make an action // The condition varibles are the "traffic lights" to tell the theads // whether the job is done and resource, the buffer in this case, available // or not. The following two condition varibles "condc" and "condp" are // the traffic lights for consumer thread and producer thread pthread cond t condc, condp; // To simplify the simulation, we use the integer varible as a buffer // The buffer stores one uint of data, that is, a integer int buffer = 0; void *producer (void *ptr) int i; for (1-1 ; i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
