Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Windows OpenGL
I'm creating a game engine that utilizes multiple threads. In its current state, it uses two threads: one for handling windows messages (main thread), and another specifically for OpenGL.
 
Its not of immediate concern, but I have discovered that the main thread bottlenecks the OpenGL thread. What this means is that if the update loop of the main thread takes longer to complete than loop in the other, it will slow it down. If the main thread is slower, the GL thread will only update as fast as the main thread.
 
Obviously this isn't a major issue since the main thread will never have more to do than the OpenGL thread, but I'd like to know whats going on to better understand the winapi and OpenGL on windows.
 
Does anyone know whats happening here?
 
Note: The GL thread will update normally whenever I interact with the window (move it, resize it, etc).
Posted 6-Jul-11 20:46pm
Edited 6-Jul-11 20:57pm
v2
Comments
Chuck O'Toole at 7-Jul-11 1:58am
   
How many cores / cpus on your machine?
James_722 at 7-Jul-11 2:08am
   
4 cores (Intel q6600)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

In your situation, 2 things affect time sharing
1) Thread priorities
2) If thread(s) is/are blocked due to waiting for a shared resource (a critical section for example)
 
If your OpenGL thread has a higher priority than the main thread, AND there are no blocking situations, it is not possible for your main thread to slow down your OpenGL thread.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

After a little more experimentation I solved the issue.
 
I was monitoring the frame rate coming from the GL thread by displaying it in the window's title.
 
When I stopped displaying the frame rate it was clear that the GL thread was no longer being affected by the main.
 
What I have concluded is that SetWindowText() must not finish execution until it has passed through the windows messaging system. the GL thread could not continue until that message was processed and thus linked its performance to that of the main thread.
 
I appreciate the help I received and hopefully this post will helpful to others.
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 7 Jul 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100