Reputation: 21212
I have seen some time ago people discussing about the new multithreading in Delphi XE and about the fact that Delphi has some 'native' problems because of the way it implements multithreading. And they were recommending some external libraries to replace the default Delphi multithreading.
Can you point me to some documentation and the most popular multithreading library for Delphi XE? Thanks
Upvotes: 26
Views: 8184
Reputation: 5545
gabr probably mentioned main new additions. What was left probably is the new overloads for TThread.Synchronize
and TThread.Queue
which can now execute anonymous methods.
Upvotes: 8
Reputation: 26850
[You can set thread name: TThread.NameThreadForDebugging
.] (implemented in D2010 as David pointed out)
You can create anonymous thread (a thread that executes anonymous function and doesn't need a TThread descendant object): TThread.CreateAnonymousThread
.
Delphi threading frameworks are discussed here:
Upvotes: 28
Reputation: 1938
I believe all of newly introduced features were covered already.
For the documentation part, here is an archived copy on classic tutorial book Martin Harvey. Multithreading - The Delphi Way. After reading you will most likely realize what there is no real need for any contributed libraries (except, maybe, the thread pool), remember, frameworks are not simplifying things for you, they also depriving you from the fine-grain control.
Upvotes: 7
Reputation: 34929
TThreadedQueue was introduced in XE.
I find it useful for passing information from worker threads to the main thread or other consumer threads. The last part, having multiple consumer threads, was buggy unfortunately. There was a bug in TMonitor, a class introduced by Delphi 2009, used to synchronize access to the queue in TThreadedQueue.
This has been fixed for XE2. See tthreadedqueue-not-capable-of-multiple-consumers
Upvotes: 5
Reputation: 43053
I think the "native" issues you are talking about are not related to the way TThread
is implemented, but to other aspects of the RTL:
string
and dynamic arrays) are implemented with an asm lock
opcode to have atomic reference counting (InterlockedDecrement/InterlockedIncrement in x64), which may also scale badly on multi-threaded applications (that is, all cores freezes when this opcode is executed - even if newer CPUs made progress about this, an RCU implementation may scale better).Those weakness are common to all multi-thread libraries - even OTL will suffer about this. They do exist since very early Delphi versions, and are still there with Delphi XE2. The 64 bit implementation is similar (even slower), and the Mac OS platform shares the very same implementation.
Please see this other SO question about how to write scaling multi-threaded applications in Delphi.
To be honest, both points above will appear only on some very specific kind of applications.
So there is nothing to worry about multi-threading in Delphi, if you know those points, and do not abuse of memory manager calls or string process in your threads.
Upvotes: 14
Reputation: 37221
Also, in addition to what's already been mentioned:
TExternalThread
wrapper for external threads (accessible via TThread.CurrentThread
class property).SyncObjs
unit: support for condition variables, TLightweightEvent
, TLightweightSemaphore
, TSpinLock
, TSpinWait
, TInterlocked
and more...Upvotes: 16