obrienslalom said:Calling sleep is almost the same as a //TODO in your code. It is very rare that it is the appropriate way to solve the problem. What you are normally doing is saying, "wait until x happens, which will probably happen in under t time". You should always try to find a way to verify that x has happened and then send a notification to the waiting thread.
I sometimes use sleep to prove that my issue is a synchronization issue and then come back and write the logic. Of course, there are cases where it is necessary.
not sure i would go THAT far...
example code for an app that gets text from a serial port.
i have events that get the data and hold it in a buffer async from the main logic.
i have other code that does sleep() and checks the buffer for the needed data.
so the sleep use does allow my code to wait for the serial port to get the data and for my serial event to fetch it.
due to the data i can not just fire on a new char, i have to wait for a string of text and a newline to arrive.