Bill Baxter dnewsgroup at
Thu Nov 16 00:02:36 PST 2006

Alexander Panek wrote:
> Does the output really have to be with 50Hz, or do you simply want to 
> trigger output with a frequency of 50Hz? You could start a thread 
> everytime that puts that stuff onto the screen, while your main loop 
> just continues.
> Apart from that you could also use a seperate thread that outputs a 
> stack that is filled up by your main routine.
> How exactly do you ensure that your main routine runs with ~1kHz? Sounds 
> quite need-to-hack-timer-interrupt-ish :P .
> Alex
> nobody_ wrote:
>> How do I make a thread run at a certain rate (x times a second ) 
>> without bothering the rest of the program?
>> The main-loop runs at about 1000hz and I need to output some of the 
>> data to my screen at about 50/60Hz.
>> I don't care whether there are frames lost, as long as the main loop 
>> runs correctly.
>> Or shouldn't I use a seperate thread for the screenoutput?
>> Thx

You probably need to be more specific about what you plan to use for 
drawing the output, because different libraries have different ways to 
achieve what you want.  For instance GLFW has a function 
"glfwSwapInterval()" to which you can pass the desired frame rate of 
your rendering.  Internally it presumably has some sort of timer and 
sleep call for suspending itself between renders.  I think SDL also has 
something like that.


More information about the Digitalmars-d-learn mailing list