#Producer-Consumer Program with Semaphores

11 messages · Page 1 of 1 (latest)

crude adderBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

past wing
#

What are you stuck with?

#

The code looks extremely error-prone. Manually locking and unlocking mutexes is way too difficult to maintain.

midnight shadow
#

The program won't go through when I try to run it

past wing
#

You probably have a deadlock.

#

Use std::lock_guard or even better make a wrapper that does it automatically.

midnight shadow
past wing
#

That is unfortunate.

midnight shadow
#

I was using unique lock before for this code but we were asked to use semaphores now

past wing
#

It's excessively and unnecessarily difficult, bad practice and just all-around bad.

#

Well, I recommend you start debug printing. Print out whenever you lock and unlock a mutex and from where. Then try to see where you locked something and forgot to unlock it.