Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: Threading Crashes  (Read 1304 times)
harikumar001
Customers
Community Member
*****
Posts: 65


« on: October 01, 2010, 07:58:14 AM »

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):

Code:
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:

Code:
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
Logged
Mithrandir
Community Member
*
Posts: 325


« Reply #1 on: October 01, 2010, 08:16:46 AM »

Did you enable multithreading for your TVEngine?
Logged
TecnoBacon
Customers
Community Member
*****
Posts: 305


WWW
« Reply #2 on: October 01, 2010, 12:04:01 PM »

Try without enabling threading in TV, I found that TV is not really thread safe, sounds like you are hitting locked vars that TV is trying to use. We were having to lock all data while TV is running and that was just unacceptable. It might have something to do with GC as calling it during threading was total disaster.
Logged

www.TecnoBacon.com - the other side of the Bacon family! 3D Development, Music and more.
harikumar001
Customers
Community Member
*****
Posts: 65


« Reply #3 on: October 02, 2010, 05:30:20 AM »

Thank you Mithrandir and TechnoBacon

I have tried implementing threading in different ways (separating data, separating functions) but still I am not getting the performance that I need. A lot of my update code deals with numerous checks and constant updates to meshes and their positions. So I cannot find very many blocks of codes which can be executed independent of each other in threads.

I separated some of checks into different frames and on my laptop i get 3-4FPS, on my desktop 17FPS. The application is really slow and the performance keeps on decreasing as I add more and more meshes.

I read different techniques for implementing multi threading but most of them are not helpful for me because of a lot my checks are inter-dependent.

I see a lot of applications like the PlanetX Map editor which offers good levels of performance. How to achieve that?

Logged
Shadowsong
Customers
Community Member
*****
Posts: 328


« Reply #4 on: October 02, 2010, 06:35:42 AM »

Well the question is, how fast is your application without multi-threading?
If you have a complex program with a lot of stuff to calculate, you should first try to make it performant at single-threading.
In most cases multi-threading will not make your app faster if it is not already programmed in a very good and clean way.

So my advice is try single-threading first and analyse the performance there.

Also I believe splitting the program into a rendereing and an updating thread does not make much sense since the rendering is done mostly on GPU anyway (and not CPU).
It would only make sense to split your update-method into two sub-threads which both use CPU and can be separated to two cores.
« Last Edit: October 02, 2010, 06:37:30 AM by Shadowsong » Logged
arnienet
Customers
Community Member
*****
Posts: 263


WWW
« Reply #5 on: October 02, 2010, 07:58:17 AM »

You could also split ProcessLotsOfStuff between alternate loops, or only call it every 500ms for eg. What fps do you get if you don't call ProcessLotsOfStuff?
Logged

Total Dev time = 50% to code, 50% to test, 50% to find errors, 50% to fix, that's why it takes twice as long.

Dawn World MMO
harikumar001
Customers
Community Member
*****
Posts: 65


« Reply #6 on: October 03, 2010, 11:44:03 AM »

Thank you arnienet and Shadowsong

I have been working on my code trying to optimize it. Following observations were made:

One problem for low frame rates on my laptop was, Anti Aliasing was enables with 10 samples. Removed that, and frame rates up from 3 to 255.

Another problem is some really heavy meshes that my application uses (triangle count over 36000). Users can add multiple meshes into the scene dynamically. The update calculations for such meshes are really heavy.

Threading some functions within Update is giving lower FPS than when running on a single thread.

I have decided to keep my application single threaded to avoid unexpected bugs.

Btw, is scaling down a .X model in 3DS Max and then scaling it up in TV3D gonna help. The final result is the same but the original .X would be smaller in size. Feels like a dumb question to ask.

Regards

Logged
arnienet
Customers
Community Member
*****
Posts: 263


WWW
« Reply #7 on: October 03, 2010, 04:26:08 PM »

Good to hear you've found some optimisations, I generally only use X2/X4 antialais with
reasonable resolution, it gives good results.

Can I ask why 36,000 polys for a mesh? I wonder if you need that many? 3DS Max may be
exporting that many, but generally real time 3D apps don't use that many per model. If you can make the model with less polys, but looking the same, do that to reduce your over all poly count.

Are you familiar with LOD concepts? You basically have 3 models looking the same with 3
levels of details (different poly counts), the further an object is away from the camera the lower the LOD model (lower poly count) you draw in the scene (it depends on the size of your scene as to whether it's worth doing though).

Scaling the model will not increase the fps, its the poly count that kills fps mainly.



« Last Edit: October 03, 2010, 04:29:22 PM by arnienet » Logged

Total Dev time = 50% to code, 50% to test, 50% to find errors, 50% to fix, that's why it takes twice as long.

Dawn World MMO
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks