Hey Guys,
Implemented threading in my application. I separated Rendering & Update into two different threads. I use Mutex to make sure that only 1 thread enters critical code at one time. But still the application crashes. My computer gets restarted sometimes.
The errors I see are different. I once saw error with TV_DrawText, once TV_EndText call. And my application has actually slowed down badly. It was working better without threading.
How do I optimize performance? Cant figure out whats going wrong.
My draw thread function looks like this (only rendering happens here):
while(Running)
{
mutex.waitone();
TV.Clear(false);
scene.RenderAllMeshes();
TV.RenderToScreen();
mutex.ReleaseMutex();
Application.DoEvents();
}
My update thread has the below structure (everything else other than rendering happens here:
while(Running)
{
mutex.waitOne();
GetInput();
ProcessLotsOfStuff(); //Heaviest part of the application
mutex.ReleaseMutex();
}
If you see, even though both threads run in parallel, one is waiting for the other to start execution. I am forced to do this as the update thread updates a lot of variables and meshes while executing. So I have to make rendering stop during this process which is affecting performance. To add to my problems, I am getting different errors.
Performance is really bad with the code above. Cant even move my mouse properly. What can be done? Any pointers?
Regards