Added semaphores for synchronization in the buffer methods.