Main loop, threads, and so on... How?
Hi,
I have an openGL application that renders once in a main loop. The main loops also contains the messaging functions. It basically looks like:
bool CMyApp::mainLoop()
{
while (true)
{
MSG message;
while(getWindowMessage(message))
processWindowMessage(message);
... other things
renderScene();
}
}
My question is: if I run another thread next to the main one, will the thread be processed automatically every x miliseconds, or will it depends on how long the function "renderScene()" takes?
I tried to set-up a communication thread (sockets) for my application but that makes my whole application much slowlier!! I have no idea why this is happening
Thanks for your help :)
Isn't a thread similar to a second application running in parallel to the main application?
My communication thread's loop needs to be run every 10-30 miliseconds approximately while the loop of my main application will be run every 50-200 miliseconds (depending on how complex the openGL scene is)
My communication thread's loop needs to be run every 10-30 miliseconds approximately while the loop of my main application will be run every 50-200 miliseconds (depending on how complex the openGL scene is)
In windows, if you create another thread with the same priority, the two threads will take turns. Each thread will run until it uses up or gives up its alloted time. When that happens the other thread starts running.
If you create another thread and it never gives up any of its time (by waiting for I/O or Sleep), then your original thread will run at half speed.
As a side note, here is a quick question about your pseudocode. What will happen if your application generates/receives two messages every frame?
If you create another thread and it never gives up any of its time (by waiting for I/O or Sleep), then your original thread will run at half speed.
As a side note, here is a quick question about your pseudocode. What will happen if your application generates/receives two messages every frame?
Thank you for your explanation JohnBolton!
If my application receives 2 (or more) messages every frame, the messages are processed until the message pipe is empty, then rendering is performed again
If my application receives 2 (or more) messages every frame, the messages are processed until the message pipe is empty, then rendering is performed again
BTW, how often is Windows switching between threads (if both threads are all the time active (not sleeping))?
Is it less than 10 miliseconds?
Is it less than 10 miliseconds?
Another quick question:
If I access some data in thread1 and do not want thread2 to access the data at the same time, what command should I use for "protected access"?
If I access some data in thread1 and do not want thread2 to access the data at the same time, what command should I use for "protected access"?
Quote:Original post by Floating
Another quick question:
If I access some data in thread1 and do not want thread2 to access the data at the same time, what command should I use for "protected access"?
Look up "CRITICAL_SECTION".
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement