Anyone know how to create this Producer-Consumer algorithm with infinite loop that let the user stop the Threads and start any times that the user want?

I have always a Deadlock and I'm not able to see how to avoid it.

Thanks,