??? 02/27/08 16:55 Modified: 02/27/08 16:59 Read: times |
#151544 - Could this hang forever? Responding to: ???'s previous message |
Chris said:
Wait(5); //wait for 5ms Time_Out(500ms); //time out = 1 second; while(DRIVER); <<<<<<<\ while(!DRIVER); <<<<<<</ These are the question, why driver and then !....? Wait(0); if(DRIVER) Although it's hard to say for sure without knowing what Time_Out() does and without knowing how DRIVER is defined, this snippet looks a little bit dangerous to me. If we assume the likely case that DRIVER is just a name for a digital input, then you're going to get stuck in one or the other of the 'while' loops if the signal isn't wiggling up and down. Can you absolutely guarantee that DRIVER will always be wiggling up and down? If not, then you need something that checks both the input and a timer of some sort within the polling loops. If the input state changes as expected before the timer expires, fine; everyone lives happily ever after. However, if the timer expires before the input changes, then your program can handle the situation gracefully (perhaps by posting an error, or resetting whatever is controlling the input signal, or ???) instead of just stupidly hanging in the loop forever. -- Russ |
Topic | Author | Date |
Code snippet analysis | 01/01/70 00:00 | |
Context needed! | 01/01/70 00:00 | |
Correction![]() | 01/01/70 00:00 | |
analyzed | 01/01/70 00:00 | |
Just High-Low | 01/01/70 00:00 | |
No, he was right | 01/01/70 00:00 | |
You're Right | 01/01/70 00:00 | |
Depends | 01/01/70 00:00 | |
neon | 01/01/70 00:00 | |
Both wrong | 01/01/70 00:00 | |
glad I 'illuminated' :) | 01/01/70 00:00 | |
Equivalent to ... | 01/01/70 00:00 | |
thank guys.... | 01/01/70 00:00 | |
Could this hang forever? | 01/01/70 00:00 | |
hanging cha.. eh loops | 01/01/70 00:00 | |
Not forever by design | 01/01/70 00:00 |