🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

thread and network problem

Started by
1 comment, last by bobatefrei 22 years, 4 months ago
I''m writing a multiplayer version of my flight "simulation". I use a thread to poll the network event, but this causes a little problem: every 2 or 3 sec, there the game is blocked (FPS goes down from 100 to 10). I tried to decrease the priority of the poll thread and increase the priority of the main one: this is a bit better, but there is always slowdown problems...
Advertisement
Well, if you have another thread that just checks the network event, you might not want to poll for it, just block in a Wait for it?
The only problem with blocking is that the thread must transition to Kernel mode (I believe) and that takes precious CPU cycles. This is especially prevalent if you are constantly blocking, awaking, then blocking again. In your case though, it might not be as bad as I''m making it out.

Also you should never poll for anything unless absolutely necessary. Always use whatever synchronization mechanisms the operation system provides you. For instance it is better to call WaitForSingleObject(threadhandle, INFINITE) than to call GetThreadExitCode(..., ...) and poll on a STILL_ACTIVE result when waiting for a thread to terminate.



Dire Wolf
www.digitalfiends.com
[email=direwolf@digitalfiends.com]Dire Wolf[/email]
www.digitalfiends.com

This topic is closed to new replies.

Advertisement