Re: "while loop" in a thread

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



runcyclexcski@xxxxxxxxx wrote:
"continuously" in my case means a frame delivered every 300
milliseconds. I may need to go to 30 millseconds down the road. The
while loop checks if a new frame is available (using function that is
in a OEM library that came with the camera), and when a new frame is
available, the program displays it.

Even if I don't display any frames (essentially, a blank while loop,
for testing purposes) I still get the freeze.

What matters here is what happens when you check and a new frame is not available. If you don't have any way to suspend the thread at that point then you are asking the processor to spend all its time rechecking.

You can insert a Sleep() call in the animation loop to use less CPU time.
If Sleep() is precise enough so that I don't miss a frame, OK.

Sleep() will generally give you a resolution of 10 msec. But neither polling continuously nor Sleep() is a good design.

You can make the animation event-driven instead of an unbounded loop.
When the incoming data completes a frame call the window Invalidate,
then return to the message pump.

See, I use events elswhere in my app, but I don't understand the
"phylosophy" behind events. Does't the event triggering istelf imply a
while loop somewhere in the system waiting for the event to happen?

No. Any while loop, anywhere, will attempt to burn up all available CPU time. Waiting for an event is much more efficient. It works approximately like a 10 msec interrupt: At each interrupt the OS checks for pending events and decides which thread to execute next.

--
Scott McPhillips [VC++ MVP]

.



Relevant Pages

  • Re: This Weeks Finds in Mathematical Physics (Week 232)
    ... as long as you specify both a loop, a base point and a coordinate frame ... A reference frame is not enough. ... By specifying a path and a loop, do you mean homotopy classes of these ... The one exception is a big bang with a total deficit of *exactly* 4Pi. ...
    (sci.physics.research)
  • Re: Batch malloc
    ... Why would the code block, either loop conditional or loop body, need to be ... one thing you didn't mention was that return(and possibly sizeof() ... You remove the called frame from the stack. ...
    (comp.programming)
  • Re: Time based loop limiting
    ... You also use the elapsed time in your physics, so the physics engine ... is not tied to your frame rate. ... I could try calling sleep with a float that represents the difference ... between the next time I want the loop to run and the current time. ...
    (comp.lang.ruby)
  • Re: widget updating issue
    ... I have a frame with a number of labels, ... When the "Update" button is pressed I execute a linux rsh command to ... It takes about 8 seconds for the loop of 6 ...
    (comp.lang.tcl)
  • Re: GridBagBlues #2376234
    ... Now there is a large blank area at the bottom of the frame. ... That approach produces generally expected row heights as long as each ... iteration of the loop increases the height of at most one row. ... If the layout produces excess row height (empty space at bottom of container), order the adds by GridBagConstraint.height, GridBagConstraint.gridy ascending. ...
    (comp.lang.java.gui)