Click here to Skip to main content
15,912,069 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Embedded Systems, Asembly and C/C++ Pin
CodingLover31-Oct-11 23:47
CodingLover31-Oct-11 23:47 
GeneralRe: Embedded Systems, Asembly and C/C++ Pin
Richard MacCutchan31-Oct-11 23:27
mveRichard MacCutchan31-Oct-11 23:27 
GeneralRe: Embedded Systems, Asembly and C/C++ Pin
CodingLover31-Oct-11 23:50
CodingLover31-Oct-11 23:50 
GeneralRe: Embedded Systems, Asembly and C/C++ Pin
Richard MacCutchan1-Nov-11 0:00
mveRichard MacCutchan1-Nov-11 0:00 
AnswerRe: Embedded Systems, Asembly and C/C++ Pin
INNMorris3-Nov-11 11:23
INNMorris3-Nov-11 11:23 
QuestionSetTimer Pin
columbos1492731-Oct-11 2:49
columbos1492731-Oct-11 2:49 
AnswerRe: SetTimer Pin
David Crow31-Oct-11 3:10
David Crow31-Oct-11 3:10 
AnswerRe: SetTimer Pin
Luc Pattyn31-Oct-11 3:12
sitebuilderLuc Pattyn31-Oct-11 3:12 
Hi,

1. first a general note: empty loops that spin the CPU until some condition is met are a bad idea as they waste CPU cycles. You should look first for an event-based approach, where the system tells you something happened rather than you permanently polling for it. If no event-based solution exists, your loop should relinquish the CPU by including a "sleep" of a couple of milliseconds at least, so other things can happen while you wait.

2. I don't know on which thread your while loop is executing; if it is on the main thread (the same one that would execute your OnTimer code), then there is no way the app can do both things at the same time: the OnTimer event will only get handled when the while has finished, causing a deadlock. Now read again my #1. If OTOH the while loop is running on another thread, then I don't know why your setup is failing.

3. If all you need is waiting for some input with a time-out, and still assuming there isn't an easy event-based approach, then I'd recommend this (pseudo-code!):
Time limit = now() + maximumWaitTime;
for(;;) {
    try getting the input
    if (success) break;
    sleep(someDelay);          // don't spend all CPU cycles in this polling loop
    if (now() > limit) break;  // timed out
}


Smile | :)
Luc Pattyn [My Articles] Nil Volentibus Arduum

AnswerRe: SetTimer Pin
Erudite_Eric31-Oct-11 3:50
Erudite_Eric31-Oct-11 3:50 
AnswerRe: SetTimer Pin
Chuck O'Toole31-Oct-11 10:06
Chuck O'Toole31-Oct-11 10:06 
GeneralRe: SetTimer Pin
Erudite_Eric31-Oct-11 21:12
Erudite_Eric31-Oct-11 21:12 
GeneralRe: SetTimer Pin
Chuck O'Toole1-Nov-11 2:58
Chuck O'Toole1-Nov-11 2:58 
GeneralRe: SetTimer Pin
Erudite_Eric1-Nov-11 3:07
Erudite_Eric1-Nov-11 3:07 
GeneralRe: SetTimer Pin
Chuck O'Toole1-Nov-11 3:18
Chuck O'Toole1-Nov-11 3:18 
GeneralRe: SetTimer Pin
Erudite_Eric1-Nov-11 3:30
Erudite_Eric1-Nov-11 3:30 
GeneralRe: SetTimer Pin
Chuck O'Toole1-Nov-11 3:44
Chuck O'Toole1-Nov-11 3:44 
GeneralRe: SetTimer Pin
Erudite_Eric1-Nov-11 4:48
Erudite_Eric1-Nov-11 4:48 
GeneralRe: SetTimer Pin
Chuck O'Toole1-Nov-11 5:11
Chuck O'Toole1-Nov-11 5:11 
GeneralRe: SetTimer Pin
Erudite_Eric1-Nov-11 6:43
Erudite_Eric1-Nov-11 6:43 
GeneralRe: SetTimer Pin
Chuck O'Toole1-Nov-11 7:51
Chuck O'Toole1-Nov-11 7:51 
GeneralRe: MSDN:Preventing Hangs in Windows Applications Pin
Goto_Label_1-Nov-11 9:17
Goto_Label_1-Nov-11 9:17 
GeneralRe: MSDN:Preventing Hangs in Windows Applications Pin
Chuck O'Toole1-Nov-11 10:14
Chuck O'Toole1-Nov-11 10:14 
GeneralRe: MSDN:Preventing Hangs in Windows Applications Pin
Erudite_Eric2-Nov-11 7:02
Erudite_Eric2-Nov-11 7:02 
GeneralRe: MSDN:Preventing Hangs in Windows Applications Pin
Chuck O'Toole2-Nov-11 9:16
Chuck O'Toole2-Nov-11 9:16 
GeneralRe: MSDN:Preventing Hangs in Windows Applications Pin
Erudite_Eric2-Nov-11 11:25
Erudite_Eric2-Nov-11 11:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.