So in my code, I'm adding and removing items from a bounded buffer and if an item cannot be added or removed then the code waits. This is the wait I'm using for add.
Code:
void add_to_buffer(int value) {
pthread_mutex_lock(&mutex);
while (count == BOUNDED_BUFFER_SIZE){
pthread_cond_wait(&cond, &mutex);
}
bounded_buffer[count] = value;
count++;
pthread_cond_signal(&cv);
pthread_mutex_unlock(&mutex);
}
Now when I test this, I have a server window and another window where I run curl commands. Now if I run enough add commands to the point where the buffer is full and it has to wait, I can't input another command on my terminal window while the server is waiting due to the fact that the mutex is locked. I tried opening up a new terminal window and do a remove command and it removes the value from the buffer however the previous add command doesn't add anything new to the bounded buffer.
So did I not implement the wait correctly or am I not testing it correctly?