Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Architekt

Windows multithreading?

This topic is 5976 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Perhaps I''m confusing terminology..if so someone please correct me. Anyways, I''ve got a mouse update/polling function that I''d ideally like to be automatically called every certain number of times per second (roughly of course). I had used the Windows SDK CreateThread method to try and get that to work (I''m skipping over the non important stuff here), and it just gets called once and then exits. That makes sense to me, cause it''s just starting a new thread, which isn''t supposed to be called again after it finishes execution. But what I can''t figure out is how to get my update/polling function to be run in a separate thread AND be called repeatedly a certain number of times per second. Can someone explain or at least point me to the right MSDN page? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
I don''t have time to go into detail now, but why not make the function your thread runs contain a simple loop?

  
// pseudo code

int someFunction()
{
while(gameIsRunning)
{
if(currenttime==nextTime)
{
pollInput();
nextTime=currenttime+100;
}
}

return 0;
}


Basically, just keep looping through as long as the game is still running. Get the time, and if it''s been a certain inverval (say 100 milliseconds) since the last time you polled, do it again, then set the next time to try to 100ms in the future.

Make sense? Someone will probably give a better answer later on anyway heh.

Anthracks

Share this post


Link to post
Share on other sites
Don''t forget that if you use CreateThread you cannot use the C runtime library. Use beginthread instead.

Share this post


Link to post
Share on other sites
Check your SDK both WIN32 and DX (if u are using it) for timer functions. Once you setup the timer, it sends your app messages handled by your window message procedure(WM_TIMER). From here you could either:
1.Don't use threads at all, Poll using a procedure, it being the WM_TIMER message handler. (No extra overhead since u have to deal with the message loop.)
2.In the WM_TIMER message handler create/destroy/sleep/wake.. your "input thread".
3.Same as one but put your rendering and processor intensive code into a seperate lower priority thread (not that much lower than your main/input thread). This will give you best results performance and quality wise.

-potential energy is easily made kinetic-

Edited by - Infinisearch on January 13, 2002 1:15:45 PM

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!