Advertisement

thread and network problem

Started by February 14, 2002 04:53 AM
1 comment, last by bobatefrei 22 years, 11 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...
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?
Advertisement
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