View RSS Feed


Going multithreaded...

Rate this Entry
Well, after having dabbled on this topic many times before - I decided I'd do AMD's latest chips a favour and make my code benefit from all that threaded goodness they can offer . So, I dove into the code archive and found some bits and bobs that had been gathering dust for a almost 2 years now... Turns out that since then a few bits were depreceated with FPC 2.6.0 . So I changed all the Execute() calls to Start() and hey presto, the old code had some life breathed back into it.

So, after a bit of sitting around a couple weeks back I thought I might make some of my code benefit from the now common as grey weather in england this time of year multicore chips we all learnt to love back in the day. Multi threaded loaders, getting those pesky CPU based rotations and other such horros to work in parrallel and what not. So I set about making a generalized threading unit to be used with prometheus. It now works - point it at a procedure (sort of rather literally as it were) and tell it when to start working some magic and then you can launch 1, 2, 8, 16, 50 - or as the testing phase I ran had a crack at, 300 threads in parrallel. In short, it works - but any test with more than about 6-8 threads tooks this old dual core penryn deal I have here on holiday to breaking point

So, now that I know it works, I've started rolling some utlity functionality - such as a function to get the ideal number of threads, work queues (lists of things for each thread to do), management for those queues (eg. Split into 2 threads, merge...), wait for loads of threads to finish, prioritizing threads (eg. Thread A can only be safely run after thread B is done, or thread C gets to a certain point)... All the goodnes that has me tearing up some big bits of code I previously thought were 'efficient enough' to make prometheus that bit faster. And in turn, everything I make that bit faster too. For now, I tested some of the TMX goodness and let me tell you - its a not much faster (maybe the fault of my running it on a mechanical laptop HDD). Though the fact you can now load small TMXs in under 90ms whereas you had to wait a whole 120 before might not help you much... It is a start

Edit: almost forgot, for anyone wanting to get into threads and whatnot, AthenaOfDelphi put up a great tutorial here on PGD which is where I picked up the large majority of what I know on the topic - however small that is and you can find the first part right here: (I reckon they should still compile great - with the only compiler warning as of FPC 2.6.0 being that TThread.Resume is obsolete for some techincal reason you can try to understand here: (as if things sort of werent secure enough already )
Click image for larger version. 

Name:	PM Threads IT1 Test.jpg 
Views:	355 
Size:	32.0 KB 
ID:	955

Submit "Going multithreaded..." to Digg Submit "Going multithreaded..." to Submit "Going multithreaded..." to StumbleUpon Submit "Going multithreaded..." to Google

Updated 30-10-2012 at 07:24 PM by code_glitch

Tags: None Add / Edit Tags


Comodo SSL