Board index » delphi » Re: The curse of the Synchronize II.
Ritchie Annand
![]() Delphi Developer |
Re: The curse of the Synchronize II.2004-11-11 05:51:42 PM delphi27 In article <XXXX@XXXXX.COM>, XXXX@XXXXX.COM says... QuoteAfter a mini-rant in one of the other groups, I thought that I would ask a QuoteFor years, TThread.synchronize has been deadlocking and holding up apps, ended). I haven't, though, honestly run into a case of TThread.Synchronize that wasn't caused by something else sitting waiting in the main loop. QuoteI suggest that all TwinControl descendants woulld be better off with an That said, I understand some of the pain. I set myself up a Notification system early in my foundation project with Publish/Subscribe and multithreaded environments in mind. The key addition which made it work for different scenarios was to have multiple dispatchers. You can have a threaded dispatcher (a new thread runs and calls the event handler), a pooled thread dispatcher (a thread on the pool calls the event handler), a synchronous dispatcher (the event handler is called in-line; the sender waits, as per 'normal'), a last- update dispatcher (only the most recent notification is sent) and a synchronized dispatcher (runs from Synchronize()). This lets you handle inter-thread notification with no impact on the main thread, but lets you add notification that syncs up with the main thread for GUI objects. (e.g. Target.AddChangeListener(Self,DISPATCH_SYNCHRONIZED) or Target.AddChangeListener(TMethodListener.Create(Self,ListenMethod), DISPATCH_SYNCHRONIZED)) QuoteCould something like this be added to D8/ .NET? don't have an infinite number of kinds of notification :) QuoteWhat do all you other designers/developers think? What can be done to ease have F8 go to the next instruction *on that same thread* (or have I missed a new Delphi version for that? :). I've changed the way I do threads, as well. Instead of having TThread derivatives, I create objects that implement ICOREExecutable (with a sole .Execute method) which various thread-implementing objects can run. That helps focus on the classes instead of having to look at every concurrent thing you need to do as "if I let this method finish, I can not use this object ever again" (as with TThread.Execute). I keep a separate Synchronize() method (I built my own, but due to Borland hiding the bits I want, I may just make a single TThread in charge of queuing up and running Synchronize requests :), so that *anything* can do a Synchronize (you may have run into the trouble yourself that the things you CALL can not do a Synchronize). I also made a "Guard" interface that usually represents a critical, but can be swapped out for a 'deadlock detector' that uses a TryEnterCriticalSection/Sleep loop. Last month's edition of ACM's Queue magazine had an article in it about Debugging Concurrent Programs, but I am only halfway through the mag today :) QuoteRgds, Senior Software Architect Malibu Software & Engineering Ltd. Business: www.malibugroup.com Personal: nimble.nimblebrain.net Wiki: wiki.nimblebrain.net |