Multi-threaded Producer-Consumer solution for pthreads using semaphores and mutexes