Jump to content
  • Advertisement
Sign in to follow this  
Mafian

Multiple Threads

This topic is 4848 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

Hey guys... I just recently designed my own GUI System using OpenGL. While designing it, I realized that the GUI system would work better if the updating part ran on a seperate thread. However, whenever I start a new thread, the FPS of my demo drops from 2500 to about 100. Here is a synopsis of each thread: GUI THREAD: -Retrieve keyboard state -Retrieve mouse state -process each state and send appropriate messages MAIN THREAD: -Draw the GUI in its current state The funny thing is, even when i comment out all code in the GUI thread, the system still slows down DRAMATICALLY. With an empty GUI thread, the system drops from 2500 FPS to 100. I just dont understand how creating a multithreaded application is at all practical with this kind of loss. I tried switching Visual Studio to Win32 Active instead of Debug, and I tried setting the runtime library to Multi Threaded Application. Can anyone here suggest something that I could be missing?

Share this post


Link to post
Share on other sites
Advertisement
Try adding a sleep(0) at the beginning of all the other threads (rather than just comentign out their code).
See if it helps.

Share this post


Link to post
Share on other sites
Sleep(0) in all threads (as Radpurv suggested), except for the updater thread, and try Sleep(10) in the updater thread. Approximately 100 times per sec ought to be enough for updating...

Share this post


Link to post
Share on other sites
Oh my... that actually worked. I tried each of the replies that you fine fellows have suggested, and here is what i came up with.

I had my updating thread sleep for 10 ms and my main thread sleep for 0 ms. This resulted favorably in restoring my blazing FPS.

Naturally, I wanted to minimize the amount of extra code, so I then had my updtaing thread sleep for 10 ms while removing the sleep within my main thread. This also produced the favorable blazing FPS.

I then changed my updating thread to Sleep for 0 ms, and left out the Sleep command in my main thread. This also produced the favorable result.

Therefore, all that was required was a Sleep(0) in my updating thread. I have solved my issue. However, I am still curious why a Sleep(0) is needed? It fixes the problem, but is Sleep(0) not equivalent to "dont sleep"?

Share this post


Link to post
Share on other sites
More or less, it infact yields control to a thread of equal or higher priority. sleep(1) on the other hand is more or less the same but can also yield to threads of lower priority.

Share this post


Link to post
Share on other sites
Quote:
Original post by _the_phantom_
More or less, it infact yields control to a thread of equal or higher priority. sleep(1) on the other hand is more or less the same but can also yield to threads of lower priority.


Thanks for the clarification :) Didn't use win32 in ages (almost 5 years).

Share this post


Link to post
Share on other sites
*tips hat*
all part of the service [grin]

I dont touch Win32 directly either, I'm using boost::thread for my MT needs, but it pays to know how things handle requests under the hood as it were

Share this post


Link to post
Share on other sites
Personally, I hate the threads. I mean, for a game they might be ok, for a web/http server they are pretty much a must, but for an MMORPG server... well, I'd rather shoot myself in the leg with a shotgun than using threads :D

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!