开发者

Are there any new parallel programing features in Delphi 2006 - XE?

Are there any 开发者_如何学Pythonnew parallel programing features in Delphi 2006 - XE?


Minimal in the releases themselves. In Delphi 2009 they added support for anonymous methods in TThread.Synchronize, and in XE they added a thread-communication queue to Generics.Collections.

But the community has contributed some interesting stuff. For example, check out OmniThreadLibrary.


There's a TThread.CreateAnonymousThread in Delphi XE which allows for simple execution of background tasks.

A trivial demo:

TThread.CreateAnonymousThread(
  procedure begin
    Sleep(10000); // replace with a real workload
  end
).Start;


IMO the most powerful and the least known multithreading feature introduced after Delphi 7 is TThread.Queue method. For example, instead of

Synchronize(
  procedure
  begin
    Form1.Memo1.Lines.Add(‘Begin Execution’);
  end);

you can use

Queue(
  procedure
  begin
    Form1.Memo1.Lines.Add(‘Begin Execution’);
  end);

TThread.Queue is an alternative to TThread.Synchronize that allows a worker thread to continue without waiting (with Synchronize call a worker thread waits until the main thread finished execution of the synchronized code) - a really nice feature that can be used as a replacement for custom message processing with PostMessage.


Since 2010 or XE threads can be named, though this is only visible in the debugger (not in e.g. sysinternals stuff like procesxp)


Currently no multicores cpu even if there are codes to run in multithreads. lock and unlock issue here is why

  1. memory manager. it is better than in the past
  2. string is reference count
  3. interface is reference count

Cheer

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜