#include #include #include #include #define MAX_LENGTH_CAP 100 You can modify MAX_LENGTH_CAP #define INIT -127 #define UNDERFLOW (0x80 + 0x02) #define OVERFLOW 0x80+ 0x01 #define BADPTR (0x80+ 0x03) #define CONSUMER_TERMINATION PROBABILITY 40 #define PRODUCER_TERMINATION_PROBABILITY 30 // =========== //sem_t ACCESS; // use a mutex instead of a binary semaphore pthread_mutex_t ACCESS = PTHREAD_MUTEX_INITIALIZER; sem_t *FULLSPOTS; sem_t *EMPTYSPOTS; struct timespec remaining; struct timespec requested_time; struct Queue{- void enqueue(struct Queue *q, char x)- char dequeue (struct Queue *q) - wvoid build(struct Queue **q, unsigned int length) - 1/ ========== void *producer(void *qptr ) --- You can modify these two constants for test and experimentation woid *consumer (void *qptr) --- void closeup (void); int main(int argc, const char * argv[])- ======== LOCKED ========== UNLOCKED ================ Don't modify this code segment
#include #include #include #include #define MAX_LENGTH_CAP 100 You can modify MAX_LENGTH_CAP #define INIT -127 #define UNDERFLOW (0x80 + 0x02) #define OVERFLOW 0x80+ 0x01 #define BADPTR (0x80+ 0x03) #define CONSUMER_TERMINATION PROBABILITY 40 #define PRODUCER_TERMINATION_PROBABILITY 30 // =========== //sem_t ACCESS; // use a mutex instead of a binary semaphore pthread_mutex_t ACCESS = PTHREAD_MUTEX_INITIALIZER; sem_t *FULLSPOTS; sem_t *EMPTYSPOTS; struct timespec remaining; struct timespec requested_time; struct Queue{- void enqueue(struct Queue *q, char x)- char dequeue (struct Queue *q) - wvoid build(struct Queue **q, unsigned int length) - 1/ ========== void *producer(void *qptr ) --- You can modify these two constants for test and experimentation woid *consumer (void *qptr) --- void closeup (void); int main(int argc, const char * argv[])- ======== LOCKED ========== UNLOCKED ================ Don't modify this code segment
C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter10: Pointers
Section10.1: Addresses And Pointers
Problem 5E
Related questions
Question
100%
Complete the following code. The goal is to implement the producer-consumer problem. You are expected to extend the provided C code to synchronize the thread operations consumer() and producer() such that an underflow and overflow of the queue is prevented. You are not allowed to change the code for implementing the queue operations, that is the code between lines 25 and 126 as shown in the Figure below. You must complete the missing parts between lines 226-261 as shown in the screenshot.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr