#Using Semaphore to contact multiple threads

1 messages · Page 1 of 1 (latest)

long wyvern
#

Hey, I'm trying this for a couple of hours now.
Following scenario: I have 3 threads -> Thread A, B and Z and one semaphore starting with 0. Letting both Threads (A and B) wait on this semaphore.
Lets assume A and B are cars and Z is an employee changing the tyres of A and B by simply changing a boolean (tires_changed) to true.
Whenever Z has changed the tires of a Thread/Car the boolean of this specific thread is set to true and the global semaphore incremented by one.
Now the problem where I'm stuck at.

Whats the best way to check in the specific thread (A and B) if the tires has been changed. I mean if the tires arn't changed for thread A it has to wait, increase semaphore and let Thread B check.

Hope I explained everything well enough 🙂

steady quiverBOT
#

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.

long wyvern
#

!solved