Welcome to the FasterThread home page
Two classes for easy multithreading, TStaticThreadPool and TDynamicThreadPool. Source, HTML-documentation and a demo project are included.
- Compatible with all versions between and including Delphi 4 to Delphi 2010
- Compatible with the free Lazarus development environment (Win32)
- Compiled and tested on Delphi 7, 2005 and 2010
- Compiled and tested on Lazarus (Win32).
Feel free to write something in my guestbook about the web page or the component or something else you want to let me and others know.
View my guestbook
Download:
Latest stable version at
files/fasterthread-113.zip
Changes:
23-09-2011 FasterThread 1.13 (Final)
- Apparently a small change was necessary to make FasterThread compatible with the RAD Studio XE2. Thanks for notifying me about this and sending a fix for the issue.
- Change: TList.List is an array of pointers in XE2, in XE1 and previous Delphi versions it was a pointer to an array of pointers. Fixed by checking the compiler version and covering both possibilities.
- DocFix: Fixed OnJobCompleted description. SyncEvents applies also to this event.
- More information available at http://docwiki.embarcadero.com/VCL/XE2/en/Classes.TList.List
06-02-2011 Updated documentation
- I regenerated the documentation and fixed one error in it (OnTerminated event documentation). Version 1.12 has been repackaged with the new documentation as a 1.12v2
08-09-2010 Experimental Linux/Mac OSX/BSD support
- Added some completely untested support for the aforementioned systems. The code is for the cpu and core count detection. If someone wants to test it and report back the results you can download the experimental version from this link:
files/fasterthread-112v2.zip
06-09-2010 FasterThread 1.11 might be the final version
- Confirmed that the components now work in Lazarus, D7, D2005 and D2010 (which is a bit stricter with the handling of threads than previous versions). I think every possible issue should be now fixed, but I will still stay around if someone has trouble getting the components to work. If you want to contribute to the project, read the To-do list at the bottom of the page. Maybe we can push another update some day with full Linux and Mac OSX support.
04-09-2010 FasterThread 1.11:
- Fix for D2010. Moved Start/Resume to AfterConstruction method instead of the constructor. This works in all versions from 4 upwards.
02-09-2010 FasterThread 1.10:
- Here it is. The new version uses TEvent objects instead of suspend and resume methods to synchronize the threads. I upped the version number with some extra so that you know this version has had a lot of internal changes. Upgrading is suggested as it fixes some bugs. Here are the changes:
- Change: Pool has to be resumed as many times as it was suspended before the Suspended property is set to false.
- Change: Named some methods with appendix "Internal" so it's obvious they are for internal use without reading any documentation.
- Change: FasterThread now uses TEvent objects to do the synchronization on both Delphi and Lazarus. This fixes the suspend/resume bugs and makes code cleaner.
- BugFix: Dynamic pool's AddJob method did not always allocate a job to any thread when it should have. Fixed.
- BugFix: GiveJob did not always allocate jobs to threads when using the ORDER allocation method. Fixed.
- BugFix: Destroying a pool did not always free all the threads in the pool. Fixed.
- If you only used a few static pools with the BASIC or PRIORITY job allocation you probably would have never noticed any problems, because in those cases the jobs were processed properly and only a small chance existed that some threads were not freed after the pool was freed.
31-08-2010 A possible synchronization bug was found, read more at the bottom of the page. A new version will be uploaded after it's completed.
31-08-2010 FasterThread 1.03:
- Nothing new, just a small change in the code.
- OnJobComplete and OnTerminated events will now get fired even when calling ExecuteJobs(true) so you can now use these events together with this call if you want.
19-08-2010 FasterThread 1.02:
- Bugfix, some changes and updates to the demo project to show how critical sections can be used.
- Bugfix: Termination of the pools was changed a bit (in TParamThread.Execute). Now after terminating the pool all assigned jobs are completed even if the threads have not yet started processing them (very rare, more common when using ORDER job allocation). Previously such jobs were simply freed, thus allowing faster termination. There was also a bug that could have caused an access violation if such jobs would have been accessed later on or when freeing the pool because the freed job was not removed from the joblist. The change also fixed this bug.
- Change: Calling Terminate will do nothing if the pool is already terminated.
- Change: If the available processing cores/threads can't be identified, amount of threads will default to 1.
- Misc: Updated the demo a little with more information and cleaner comments.
02-08-2010 Demo project:
- Fix in demo project. I had added the FasterThread unit to the project for testing, but Delphi apparently set the local file path to the unit so the unit was not found. Thanks for notifying me about this. The demo should now compile as long as the unit is in the library path.
23-07-2010 FasterThread 1.01:
- I Added some more descriptions to the demo for those who are unfamiliar with multithreading in general. I also read through the code and did some more complex testing and was able to find and fix some bugs when using the ORDER job allocation.
- Fixed double resume in ExecuteJobs and AddJob when using the ORDER job allocation.
- Bugfix in the GiveJob method. The code of ORDER job allocation had a typo in one loop and caused an access violation. Fixed.
15-07-2010 FasterThread 1.00:
- First release. Worked fine in one of my programs so I just finished the edges and published it.
Tips
- Remember that using any canvas from a thread requires you to lock and unlock the canvas properly. Even if you draw on a canvas of a bitmap that you just created and isn't used anywhere else it can still cause an access violation.
This is caused by the global GDI Object Caching in graphics.pas. You can find more information here: http://qc.embarcadero.com/wc/qcmain.aspx?d=43018
http://qc.embarcadero.com/wc/qcmain.aspx?d=55871
Some available graphical libraries are not thread safe (no lock/unlock used), but some can still be used safely in multiple threads by using a static pool and forcing the main thread to freeze until all the processing is done by using the method ExecuteJobs(true).
(Works with Graphics32-library). This will prevent the canvas handles from being freed too soon, but will also freeze the UI of the program so the user can't interact with the program until the processing is finished (similar to how it works when not using threads at all).
- Memory manager usually detects if the program is using multiple threads by checking the value of IsMultiThread variable/function. This is normally enough as FasterThread uses TThread class, which sets this value automatically, but this does not apply to threads created in a DLL. Using the components inside a DLL may require some extra work.
Bugs
To-do
Support for Lazarus is mostly platform independent, but the recognition of available processor cores is untested. Only tested Lazarus version is Win32. If someone wants to contribute to this project, testing the components on different platforms would be greatly appreciated.
About
I take e-mail at koppis01[@]luukku.com (Remove the brackets "[" "]"), if someone is interested and wants to report bugs or send other mail. If you also got a very good idea of how to improve these components, feel free to send it. I use limited time on developing these components so not all ideas will be fulfilled though, but feel free to try.
Please include the word "FasterThread" in your message subject or your e-mail will propably be removed by the spam-filter.
If possible, please, don't ask how to use the components. Instead use the demo project and documentation to find out how to use the components.
You can notify me though, in case you find that the documentation or demo project are missing some necessary information or they are not making sense. I will be happy to fix such issues if they are found.
I developed another project called KAT (Kuzin's Anime Theater) on my free time and it's available at http://kat.x10hosting.com/anime_theater_home.php. If you are into Anime, feel free to pay a visit.
You can also check out the FasterTCP components if you are interested.
If you like books you may also check out the book I just wrote. It's called "John Bennett and the Harvester of Souls" and is available on Lulu webshop as well as iBookStore. More info at http://www.lulu.com/spotlight/Kuzin