EOSERV Forum > Programming > FireMonkey - A word of warning.
Topic is locked.
Page: << 1 2 3 >>
FireMonkey - A word of warning.
Author Message
Post #153004 Re: FireMonkey - A word of warning.
Addison posted: (19th Jul 2012, 04:05 pm)

Sordie, what is your view on multi-threaded applications? What do you consider a good threading model to be? I am currently somewhat split between threads. I have a client in C++(of course it's EO), that has a networking thread, rendering thread, input thread, and then 4 content loading threads, which seems to work nice. But I am working on a remaking a old childhood game in C# and I'm not sure if I want to bother since it should be able to handle it.


Threading is mainly used as a convenience rather than an optimization. I use multi-threading all the time just because it's my style of programming.

Remember some things:

Data writes! - If you are writing to data that another thread reads or writes to then you need to have some kind of semaphore system to signal that you want the data. I'll often use "spin lock critical sections" to lock access to a single thread. Seose is a good example of bad threading. It manage data writes this way and 90% of it's crashes are because one thread of code started using an object and another bit of code deleted it halfway through =P

CPU cache. If you're using threads to optimize then keep in mind a context switch will often invalidate the CPU cache and actually end up being slower that just doing the tasks one after the other. Make sure things like small loops are serialized. In the past I've made small loop tasks threads over 5x faster just by allocating 100 bytes of dummy unused heap space to force the thread to be serialized just so it gets exclusive cache access =P

Your content loading threads are probably accessing data from the same media so this may suffer from the same problem. Thread 1 starts reading a file.. <switch to thread 2> Thread 2 starts reading a file (media has to seek) <switch to thread 1> Media seek required to resume reading..




---
http://sordie.co.uk
http://twitter.com/@SordieEO
12 years, 19 weeks ago
Post #153008 Re: FireMonkey - A word of warning.

Yeah, I might need to look up examples about serializing small loops. I have not heard that before so I may have that problem.


Making an application multi-threaded is only half the fun, you then have to make sure that its properly accessing data.


I don't know all the technicals about it, but I believe after a certain amount of threads, then you're not really optimizing at all because of the context switching.

I think I have a low enough amount that it's giving me a small performance boost. At least its making the client look like its running smoother :P


All 4 of my content loading threads run off of the same queue. And when an object is put in there, one of them takes it, loads it. Most of the time it's the first content loading thread doing the work, but the other 3 are basically backup. I am using a wait signal so they're pretty much idle threads until needed.

---
http://www.addipop.com
12 years, 19 weeks ago
Post #153013 Re: FireMonkey - A word of warning.

Anyone else watching this thread for information about the new MMO development, Go here

---
http://sordie.co.uk
http://twitter.com/@SordieEO
12 years, 19 weeks ago
Page: << 1 2 3 >>
Topic is locked.
EOSERV Forum > Programming > FireMonkey - A word of warning.