飞道的博客

Delphi线程内部

742人阅读  评论(0)

目录

Delphi线程内部

unit System.Classes;

unit System; 

unit System.Threading;  //Delphi的内部用户态线程库

如何池化线程并进行管理:

3.1、任务及其接口ITask--->TTask

 3.2、未来:也是池化的任务接口

3.3、并行库,也是池化的: 

当Application空闲Idle时你要在UI线程勤做的事情:


 

 

Delphi线程内部

 

unit System.Classes;


  
  1. function ThreadProc(const Thread: TThread): Integer;
  2. var
  3. FreeThread: Boolean;
  4. {$IFDEF MACOS}
  5. pool: Pointer;
  6. {$ENDIF MACOS}
  7. begin
  8. {$IFDEF AUTOREFCOUNT}
  9. Thread.__ObjAddRef; // this ensures the instance remains for as long as the thread is running
  10. {$ENDIF}
  11. TThread.FCurrentThread := Thread;
  12. {$IF Defined(POSIX)}
  13. if Thread.FSuspended then
  14. pthread_mutex_lock(Thread.FCreateSuspendedMutex);
  15. {$ENDIF POSIX}
  16. {$IFDEF MACOS}
  17. // Register the auto release pool
  18. pool := objc_msgSend(objc_msgSend(objc_getClass( 'NSAutoreleasePool'),
  19. sel_getUid( 'alloc')), sel_getUid( 'init'));
  20. {$ENDIF MACOS}
  21. try
  22. Thread.FStarted := True;
  23. if not Thread.Terminated then
  24. try
  25. Thread.Execute;
  26. except
  27. Thread.FFatalException := AcquireExceptionObject;
  28. end;
  29. finally
  30. Result := Thread.FReturnValue;
  31. FreeThread := Thread.FFreeOnTerminate;
  32. Thread.DoTerminate;
  33. Thread.FFinished := True;
  34. SignalSyncEvent;
  35. if FreeThread then
  36. begin
  37. Thread.DisposeOf;
  38. {$IFDEF AUTOREFCOUNT}
  39. Thread.__ObjRelease; // This will clear the thread reference that was added by setting FreeOnTerminate.
  40. {$ENDIF}
  41. end;
  42. {$IFDEF AUTOREFCOUNT}
  43. Thread.__ObjRelease; // This will clear the thread reference we added above. This may initiate disposal.
  44. {$ENDIF}
  45. {$IFDEF USE_LIBICU}
  46. // Destroy Collator Cache
  47. if IsICUAvailable then
  48. ClearCollatorCache;
  49. {$ENDIF}
  50. {$IF Defined(MSWINDOWS)}
  51. EndThread(Result);
  52. {$ELSEIF Defined(POSIX)}
  53. {$IFDEF MACOS}
  54. // Last thing to do in thread is to drain the pool
  55. objc_msgSend(pool, sel_getUid( 'drain'));
  56. {$ENDIF MACOS}
  57. {$IFDEF ANDROID}
  58. // Detach the NativeActivity virtual machine to ensure the proper relase of JNI context attached to the current thread
  59. PJavaVM(System.JavaMachine)^.DetachCurrentThread(PJavaVM(System.JavaMachine));
  60. {$ENDIF ANDROID}
  61. // Directly call pthread_exit since EndThread will detach the thread causing
  62. // the pthread_join in TThread.WaitFor to fail. Also, make sure the EndThreadProc
  63. // is called just like EndThread would do. EndThreadProc should not return
  64. // and call pthread_exit itself.
  65. if Assigned(EndThreadProc) then
  66. EndThreadProc(Result);
  67. pthread_exit(Result);
  68. {$ENDIF POSIX}
  69. end;
  70. end;

unit System; 


  
  1. { Thread support }
  2. type
  3. TThreadFunc = function(Parameter: Pointer): Integer;
  4. {$IFDEF POSIX}
  5. {$IFDEF LINUX}
  6. type
  7. TSize_T = Cardinal;
  8. TSchedParam = record
  9. sched_priority: Integer;
  10. end;
  11. {$DEFINE _PTHREAD_ATTR_T_DEFINED}
  12. pthread_attr_t = record
  13. __detachstate,
  14. __schedpolicy: Integer;
  15. __schedparam: TSchedParam;
  16. __inheritsched,
  17. __scope: Integer;
  18. __guardsize: TSize_T;
  19. __stackaddr_set: Integer;
  20. __stackaddr: Pointer;
  21. __stacksize: TSize_T;
  22. end;
  23. {$EXTERNALSYM pthread_attr_t}
  24. {$ENDIF LINUX}
  25. {$IFDEF MACOS}
  26. const
  27. PTHREAD_ATTR_SIZE = 36;
  28. SCHED_PARAM_SIZE = 4;
  29. type
  30. TSchedParam = record
  31. sched_priority: Integer;
  32. opaque: array [ 0..SCHED_PARAM_SIZE- 1] of Byte;
  33. end;
  34. {$DEFINE _PTHREAD_ATTR_T_DEFINED}
  35. pthread_attr_t = record
  36. __sig: LongInt;
  37. opaque: array [ 0..PTHREAD_ATTR_SIZE- 1] of Byte;
  38. end;
  39. {$EXTERNALSYM pthread_attr_t} // Defined in signal.h
  40. {$ENDIF MACOS}
  41. {$IFDEF ANDROID}
  42. type
  43. TSize_T = Cardinal;
  44. {$DEFINE _PTHREAD_ATTR_T_DEFINED}
  45. pthread_attr_t = record
  46. flags: UInt32;
  47. stack_base: Pointer;
  48. stack_size: TSize_T;
  49. guard_size: TSize_T;
  50. sched_policy: Int32;
  51. sched_priority: Int32;
  52. end;
  53. {$EXTERNALSYM pthread_attr_t}
  54. {$ENDIF ANDROID}
  55. type
  56. TThreadAttr = pthread_attr_t;
  57. PThreadAttr = ^TThreadAttr;
  58. TBeginThreadProc = function (Attribute: PThreadAttr;
  59. ThreadFunc: TThreadFunc; Parameter: Pointer;
  60. var ThreadId: TThreadID): Integer;
  61. TEndThreadProc = procedure(ExitCode: Integer);
  62. var
  63. BeginThreadProc: TBeginThreadProc = nil;
  64. EndThreadProc: TEndThreadProc = nil;
  65. {$ENDIF POSIX}
  66. {$IFDEF MSWINDOWS}
  67. type
  68. TSystemThreadFuncProc = function(ThreadFunc: TThreadFunc; Parameter: Pointer): Pointer;
  69. TSystemThreadEndProc = procedure(ExitCode: Integer);
  70. {$NODEFINE TSystemThreadFuncProc}
  71. {$NODEFINE TSystemThreadEndProc}
  72. (*$HPPEMIT 'namespace System' *)
  73. (*$HPPEMIT '{' *)
  74. (*$HPPEMIT ' typedef void * (__fastcall * TSystemThreadFuncProc)(void *, void * );' *)
  75. (*$HPPEMIT ' typedef void (__fastcall * TSystemThreadEndProc)(int);' *)
  76. (*$HPPEMIT '}' *)
  77. var
  78. // SystemThreadFuncProc and SystemThreadEndProc are set during the startup
  79. // code by the C++ RTL when running in a C++Builder VCL application.
  80. SystemThreadFuncProc: TSystemThreadFuncProc = nil;
  81. SystemThreadEndProc: TSystemThreadEndProc = nil;
  82. function BeginThread(SecurityAttributes: Pointer; StackSize: LongWord;
  83. ThreadFunc: TThreadFunc; Parameter: Pointer; CreationFlags: LongWord;
  84. var ThreadId: TThreadID): THandle;
  85. {$ENDIF}
  86. {$IFDEF POSIX}
  87. function BeginThread(Attribute: PThreadAttr; ThreadFunc: TThreadFunc;
  88. Parameter: Pointer; var ThreadId: TThreadID): Integer;
  89. {$ENDIF}
  90. procedure EndThread(ExitCode: Integer);
  91. { Standard procedures and functions }
  92. const
  93. { File mode magic numbers }
  94. fmClosed = $D7B0;
  95. fmInput = $D7B1;
  96. fmOutput = $D7B2;
  97. fmInOut = $D7B3;
  98. { Text file flags }
  99. tfCRLF = $1; // Dos compatibility flag, for CR+LF line breaks and EOF checks
  100. type
  101. { Typed-file and untyped-file record }
  102. TFileRec = packed record (* must match the size the compiler generates: 592 bytes (616 bytes for x64) *)
  103. Handle: NativeInt;
  104. Mode: Word;
  105. Flags: Word;
  106. case Byte of
  107. 0: (RecSize: Cardinal); // files of record
  108. 1: (BufSize: Cardinal; // text files
  109. BufPos: Cardinal;
  110. BufEnd: Cardinal;
  111. BufPtr: _PAnsiChr;
  112. OpenFunc: Pointer;
  113. InOutFunc: Pointer;
  114. FlushFunc: Pointer;
  115. CloseFunc: Pointer;
  116. UserData: array[ 1.. 32] of Byte;
  117. Name: array[ 0.. 259] of WideChar;
  118. );
  119. end;
  120. { Text file record structure used for Text files }
  121. PTextBuf = ^TTextBuf;
  122. TTextBuf = array[ 0.. 127] of _AnsiChr;
  123. TTextRec = packed record (* must match the size the compiler generates: 730 bytes (754 bytes for x64) *)
  124. Handle: NativeInt; (* must overlay with TFileRec *)
  125. Mode: Word;
  126. Flags: Word;
  127. BufSize: Cardinal;
  128. BufPos: Cardinal;
  129. BufEnd: Cardinal;
  130. BufPtr: _PAnsiChr;
  131. OpenFunc: Pointer;
  132. InOutFunc: Pointer;
  133. FlushFunc: Pointer;
  134. CloseFunc: Pointer;
  135. UserData: array[ 1.. 32] of Byte;
  136. Name: array[ 0.. 259] of WideChar;
  137. Buffer: TTextBuf;
  138. CodePage: Word;
  139. MBCSLength: ShortInt;
  140. MBCSBufPos: Byte;
  141. case Integer of
  142. 0: (MBCSBuffer: array[ 0.. 5] of _AnsiChr);
  143. 1: (UTF16Buffer: array[ 0.. 2] of WideChar);
  144. end;
  145. TTextIOFunc = function (var F: TTextRec): Integer;
  146. TFileIOFunc = function (var F: TFileRec): Integer;
  147. procedure SetLineBreakStyle(var T: Text; Style: TTextLineBreakStyle);
  148. function GetTextCodePage(const T: Text): Word;
  149. procedure SetTextCodePage(var T: Text; CodePage: Word);
  150. procedure __IOTest;
  151. procedure SetInOutRes(NewValue: Integer);
  152. procedure ChDir(const S: string); overload;
  153. procedure ChDir(P: PChar); overload;
  154. function Flush(var t: Text): Integer;
  155. procedure _UGetDir(D: Byte; var S: UnicodeString);
  156. procedure _LGetDir(D: Byte; var S: _AnsiStr);
  157. procedure _WGetDir(D: Byte; var S: _WideStr);
  158. procedure _SGetDir(D: Byte; var S: _ShortStr);
  159. function IOResult: Integer;
  160. procedure MkDir(const S: string); overload;
  161. procedure MkDir(P: PChar); overload;
  162. procedure Move(const Source; var Dest; Count: NativeInt);
  163. procedure MoveChars(const Source; var Dest; Length: Integer); inline;
  164. function ParamCount: Integer;
  165. function ParamStr(Index: Integer): string;
  166. procedure RmDir(const S: string); overload;
  167. procedure RmDir(P: PChar); overload;
  168. function UpCase(Ch: _AnsiChr): _AnsiChr; overload; inline;
  169. function UpCase(Ch: WideChar): WideChar; overload; inline;

unit System.Threading;  //Delphi的内部用户态线程库


  
  1. { TThreadPool.TBaseWorkerThread }
  2. constructor TThreadPool.TBaseWorkerThread.Create(AThreadPool: TThreadPool);
  3. begin
  4. inherited Create(False);
  5. // Priority := tpHigher;
  6. FRunningEvent := TLightweightEvent.Create(False);
  7. FThreadPool := AThreadPool;
  8. ThreadPool.FThreads.Add(Self);
  9. end;
  10. destructor TThreadPool.TBaseWorkerThread.Destroy;
  11. begin
  12. if FRunningEvent <> nil then
  13. FRunningEvent.WaitFor(INFINITE); // This waits for the Execute to actually be called.
  14. if ThreadPool <> nil then
  15. ThreadPool.FThreads.Remove(Self);
  16. FRunningEvent.Free;
  17. inherited Destroy;
  18. end;
  19. procedure TThreadPool.TBaseWorkerThread.SafeTerminate;
  20. begin
  21. if ThreadPool <> nil then
  22. ThreadPool.FThreads.Remove(Self);
  23. FreeOnTerminate := True;
  24. Terminate;
  25. end;
  26. procedure TThreadPool.TBaseWorkerThread.Execute;
  27. begin
  28. NameThreadForDebugging(Format( 'Worker Thread - %s #%d ThreadPool - %p', [ClassName, TInterlocked.Increment(WorkerThreadID), Pointer(ThreadPool)]));
  29. FRunningEvent.SetEvent;
  30. end;

如何池化线程并进行管理:

3.1、任务及其接口ITask--->TTask


  
  1. TTask = class(TAbstractTask, TThreadPool.IThreadPoolWorkItem, ITask, TAbstractTask.IInternalTask)
  2. //............
  3. public
  4. class function CurrentTask: ITask; static; inline;
  5. constructor Create; overload; // do not call this constructor!!
  6. destructor Destroy; override;
  7. class function Create(Sender: TObject; Event: TNotifyEvent): ITask; overload; static; inline;
  8. class function Create(const Proc: TProc): ITask; overload; static; inline;
  9. class function Create(Sender: TObject; Event: TNotifyEvent; const APool: TThreadPool): ITask; overload; static; inline;
  10. class function Create(const Proc: TProc; APool: TThreadPool): ITask; overload; static; inline;
  11. class function Future<T>(Sender: TObject; Event: TFunctionEvent<T>): IFuture<T>; overload; static; inline;
  12. class function Future<T>(Sender: TObject; Event: TFunctionEvent<T>; APool: TThreadPool): IFuture<T>; overload; static; inline;
  13. class function Future<T>(const Func: TFunc<T>): IFuture<T>; overload; static; inline;
  14. class function Future<T>(const Func: TFunc<T>; APool: TThreadPool): IFuture<T>; overload; static; inline;
  15. class function Run(Sender: TObject; Event: TNotifyEvent): ITask; overload; static; inline;
  16. class function Run(Sender: TObject; Event: TNotifyEvent; APool: TThreadPool): ITask; overload; static; inline;
  17. class function Run(const Func: TProc): ITask; overload; static; inline;
  18. class function Run(const Func: TProc; APool: TThreadPool): ITask; overload; static; inline;
  19. class function WaitForAll(const Tasks: array of ITask): Boolean; overload; static;
  20. class function WaitForAll(const Tasks: array of ITask; Timeout: Cardinal): Boolean; overload; static;
  21. class function WaitForAll(const Tasks: array of ITask; const Timeout: TTimeSpan): Boolean; overload; static;
  22. class function WaitForAny(const Tasks: array of ITask): Integer; overload; static;
  23. class function WaitForAny(const Tasks: array of ITask; Timeout: Cardinal): Integer; overload; static;
  24. class function WaitForAny(const Tasks: array of ITask; const Timeout: TTimeSpan): Integer; overload; static;
  25. end;

  
  1. ITask = interface(TThreadPool.IThreadPoolWorkItem)
  2. /// <summary>Waits for the task to complete execution within a specific milliseconds.</summary>
  3. function Wait(Timeout: Cardinal = INFINITE): Boolean; overload;
  4. /// <summary>Waits for the task to complete execution within a specific time interval.</summary>
  5. function Wait(const Timeout: TTimeSpan): Boolean; overload;
  6. /// <summary>Cancel the task.</summary>
  7. procedure Cancel;
  8. /// <summary>Checks the task's cancel staus. If the task is canceld, raise EOperationCancelled exception.</summary>
  9. procedure CheckCanceled;
  10. /// <summary>Starts the task, adding it to the currect queue.</summary>
  11. function Start: ITask;
  12. /// <summary>Return the task's status code.</summary>
  13. function GetStatus: TTaskStatus;
  14. /// <summary>Returns the unique integer Id</summary>
  15. function GetId: Integer;
  16. /// <summary>Task ID. Each Task has unique ID.</summary>
  17. property Id: Integer read GetId;
  18. /// <summary>Task's status code</summary>
  19. property Status: TTaskStatus read GetStatus;
  20. end;

 3.2、未来:也是池化的任务接口


  
  1. //...未来:也是池化的任务接口
  2. IFuture<T> = interface(ITask)
  3. [HPPGEN( 'HIDESBASE virtual System::DelphiInterface<IFuture__1<T> > __fastcall StartFuture() = 0')]
  4. function Start: IFuture<T>;
  5. function GetValue: T;
  6. property Value: T read GetValue;
  7. end;

  
  1. /// <summary>
  2. /// Use this record to grab a "snapshot" of a threadpool's internal state. This is useful in peering into the
  3. /// inner workings of a threadpool for diagnostic purposes. Because the accessed threadpool continues to run,
  4. /// This snapshot may not be strictly accurate. Do not depend on this structure for anything other than simply
  5. /// hinting at the internal state.
  6. /// 使用此记录可以获取线程池内部状态的“快照”。这在窥视线程池的内部工作以进行诊断时非常有用。由
  7. /// 于被访问的线程池继续运行,因此此快照可能不完全准确。除了简单地暗示内部状态之外,不要依赖于这个结构
  8. /// </summary>
  9. TThreadPoolStats = record
  10. private
  11. //...
  12. public
  13. /// <summary>Total number of worker threads within the thread pool</summary>
  14. property WorkerThreadCount: Integer read FWorkerThreadCount;
  15. /// <summary>Corresponds to the MinWorkerThreads property</summary>
  16. property MinLimitWorkerThreadCount: Integer read FMinLimitWorkerThreadCount;
  17. /// <summary>Corresponds to the MaxWorkerThreads property</summary>
  18. property MaxLimitWorkerThreadCount: Integer read FMaxLimitWorkerThreadCount;
  19. /// <summary>Number of threads waiting for work to do</summary>
  20. property IdleWorkerThreadCount: Integer read FIdleWorkerThreadCount;
  21. /// <summary>Number of global queued work requests</summary>
  22. property QueuedRequestCount: Integer read FQueuedRequestCount;
  23. /// <summary>Number of worker threads in the process of being retired</summary>
  24. property RetiredWorkerThreadCount: Integer read FRetiredWorkerThreadCount;
  25. /// <summary>Running average of CPU usage</summary>
  26. property AverageCPUUsage: Integer read FAverageCPUUsage;
  27. /// <summary>Current snapshot of CPU usage</summary>
  28. property CurrentCPUUsage: Integer read FCurrentCPUUsage;
  29. /// <summary>Shared value among worker threads to manage orderly thread suspension</summary>
  30. property ThreadSuspended: Integer read FThreadSuspended;
  31. /// <summary>Shared value among worker threads to manage orderly thread suspension</summary>
  32. property LastSuspendTick: Cardinal read FLastSuspendTick;
  33. /// <summary>Used by the monitor thread to keep from creating threads too quickly</summary>
  34. property LastThreadCreationTick: Cardinal read FLastThreadCreationTick;
  35. /// <summary>Used by the monitor thread to only create new threads when there is work to do</summary>
  36. property LastQueuedRequestCount: Integer read FLastQueuedRequestCount;
  37. /// <summary>
  38. /// When called from within a threadpool thread, returns the stats for the owning threadpool. Outside of a
  39. /// threadpool thread, this will return the stats for the default threadpool
  40. /// </summary>
  41. class property Current: TThreadPoolStats read GetCurrentThreadPoolStats;
  42. /// <summary>Returns the stats for the default threadpool</summary>
  43. class property Default: TThreadPoolStats read GetDefaultThreadPoolStats;
  44. end;

  
  1. [HPPGen(HPPGENAttribute.mkNoDefine)]
  2. TFuture<T> = class sealed(TTask, IFuture<T>)
  3. private
  4. //......
  5. protected
  6. function Start: IFuture<T>;
  7. function GetValue: T;
  8. constructor Create(Sender: TObject; Event: TFunctionEvent<T>; const Func: TFunc<T>; APool: TThreadPool); overload;
  9. end;

3.3、并行库,也是池化的: 


  
  1. TParallel = class sealed
  2. public type
  3. TLoopState = class
  4. private type
  5. //.........
  6. private
  7. //.........
  8. strict protected
  9. //.........
  10. public
  11. procedure Break;
  12. procedure Stop;
  13. function ShouldExit: Boolean;
  14. property Faulted: Boolean read GetFaulted;
  15. property Stopped: Boolean read GetStopped;
  16. property LowestBreakIteration: Variant read GetLowestBreakIteration;
  17. end;
  18. TLoopResult = record
  19. private
  20. //.........
  21. public
  22. property Completed: Boolean read FCompleted;
  23. property LowestBreakIteration: Variant read FLowestBreakIteration;
  24. end;
  25. TIteratorEvent = procedure (Sender: TObject; AIndex: Integer) of object;
  26. TIteratorStateEvent = procedure (Sender: TObject; AIndex: Integer; const LoopState: TLoopState) of object;
  27. TIteratorEvent64 = procedure (Sender: TObject; AIndex: Int64) of object;
  28. TIteratorStateEvent64 = procedure (Sender: TObject; AIndex: Int64; const LoopState: TLoopState) of object;
  29. private type
  30. //.........
  31. public
  32. class function &For(Sender: TObject; ALowInclusive, AHighInclusive: Integer; AIteratorEvent: TIteratorEvent): TLoopResult; overload; static; inline;
  33. class function &For(Sender: TObject; ALowInclusive, AHighInclusive: Integer; AIteratorEvent: TIteratorEvent; APool: TThreadPool): TLoopResult; overload; static; inline;
  34. class function &For(Sender: TObject; ALowInclusive, AHighInclusive: Integer; AIteratorEvent: TIteratorStateEvent): TLoopResult; overload; static; inline;
  35. class function &For(Sender: TObject; ALowInclusive, AHighInclusive: Integer; AIteratorEvent: TIteratorStateEvent; APool: TThreadPool): TLoopResult; overload; static; inline;
  36. class function &For(Sender: TObject; AStride, ALowInclusive, AHighInclusive: Integer; AIteratorEvent: TIteratorEvent): TLoopResult; overload; static; inline;
  37. class function &For(Sender: TObject; AStride, ALowInclusive, AHighInclusive: Integer; AIteratorEvent: TIteratorEvent; APool: TThreadPool): TLoopResult; overload; static; inline;
  38. class function &For(Sender: TObject; AStride, ALowInclusive, AHighInclusive: Integer; AIteratorEvent: TIteratorStateEvent): TLoopResult; overload; static; inline;
  39. class function &For(Sender: TObject; AStride, ALowInclusive, AHighInclusive: Integer; AIteratorEvent: TIteratorStateEvent; APool: TThreadPool): TLoopResult; overload; static; inline;
  40. class function &For(ALowInclusive, AHighInclusive: Integer; const AIteratorEvent: TProc<Integer>): TLoopResult; overload; static; inline;
  41. class function &For(ALowInclusive, AHighInclusive: Integer; const AIteratorEvent: TProc<Integer>; APool: TThreadPool): TLoopResult; overload; static; inline;
  42. class function &For(ALowInclusive, AHighInclusive: Integer; const AIteratorEvent: TProc<Integer, TLoopState>): TLoopResult; overload; static; inline;
  43. class function &For(ALowInclusive, AHighInclusive: Integer; const AIteratorEvent: TProc<Integer, TLoopState>; APool: TThreadPool): TLoopResult; overload; static; inline;
  44. class function &For(AStride, ALowInclusive, AHighInclusive: Integer; const AIteratorEvent: TProc<Integer>): TLoopResult; overload; static; inline;
  45. class function &For(AStride, ALowInclusive, AHighInclusive: Integer; const AIteratorEvent: TProc<Integer>; APool: TThreadPool): TLoopResult; overload; static; inline;
  46. class function &For(AStride, ALowInclusive, AHighInclusive: Integer; const AIteratorEvent: TProc<Integer, TLoopState>): TLoopResult; overload; static; inline;
  47. class function &For(AStride, ALowInclusive, AHighInclusive: Integer; const AIteratorEvent: TProc<Integer, TLoopState>; APool: TThreadPool): TLoopResult; overload; static; inline;
  48. class function &For(Sender: TObject; ALowInclusive, AHighInclusive: Int64; AIteratorEvent: TIteratorEvent64): TLoopResult; overload; static; inline;
  49. class function &For(Sender: TObject; ALowInclusive, AHighInclusive: Int64; AIteratorEvent: TIteratorEvent64; APool: TThreadPool): TLoopResult; overload; static; inline;
  50. class function &For(Sender: TObject; ALowInclusive, AHighInclusive: Int64; AIteratorEvent: TIteratorStateEvent64): TLoopResult; overload; static; inline;
  51. class function &For(Sender: TObject; ALowInclusive, AHighInclusive: Int64; AIteratorEvent: TIteratorStateEvent64; APool: TThreadPool): TLoopResult; overload; static; inline;
  52. class function &For(Sender: TObject; AStride, ALowInclusive, AHighInclusive: Int64; AIteratorEvent: TIteratorEvent64): TLoopResult; overload; static; inline;
  53. class function &For(Sender: TObject; AStride, ALowInclusive, AHighInclusive: Int64; AIteratorEvent: TIteratorEvent64; APool: TThreadPool): TLoopResult; overload; static; inline;
  54. class function &For(Sender: TObject; AStride, ALowInclusive, AHighInclusive: Int64; AIteratorEvent: TIteratorStateEvent64): TLoopResult; overload; static; inline;
  55. class function &For(Sender: TObject; AStride, ALowInclusive, AHighInclusive: Int64; AIteratorEvent: TIteratorStateEvent64; APool: TThreadPool): TLoopResult; overload; static; inline;
  56. class function &For(ALowInclusive, AHighInclusive: Int64; const AIteratorEvent: TProc<Int64>): TLoopResult; overload; static; inline;
  57. class function &For(ALowInclusive, AHighInclusive: Int64; const AIteratorEvent: TProc<Int64>; APool: TThreadPool): TLoopResult; overload; static; inline;
  58. class function &For(ALowInclusive, AHighInclusive: Int64; const AIteratorEvent: TProc<Int64, TLoopState>): TLoopResult; overload; static; inline;
  59. class function &For(ALowInclusive, AHighInclusive: Int64; const AIteratorEvent: TProc<Int64, TLoopState>; APool: TThreadPool): TLoopResult; overload; static; inline;
  60. class function &For(AStride, ALowInclusive, AHighInclusive: Int64; const AIteratorEvent: TProc<Int64>): TLoopResult; overload; static; inline;
  61. class function &For(AStride, ALowInclusive, AHighInclusive: Int64; const AIteratorEvent: TProc<Int64>; APool: TThreadPool): TLoopResult; overload; static; inline;
  62. class function &For(AStride, ALowInclusive, AHighInclusive: Int64; const AIteratorEvent: TProc<Int64, TLoopState>): TLoopResult; overload; static; inline;
  63. class function &For(AStride, ALowInclusive, AHighInclusive: Int64; const AIteratorEvent: TProc<Int64, TLoopState>; APool: TThreadPool): TLoopResult; overload; static; inline;
  64. class function Join(Sender: TObject; AEvents: array of TNotifyEvent): ITask; overload; static;
  65. class function Join(Sender: TObject; AEvents: array of TNotifyEvent; APool: TThreadPool): ITask; overload; static;
  66. class function Join(Sender: TObject; AEvent1, AEvent2: TNotifyEvent): ITask; overload; static; inline;
  67. class function Join(Sender: TObject; AEvent1, AEvent2: TNotifyEvent; APool: TThreadPool): ITask; overload; static;
  68. class function Join(const AProcs: array of TProc): ITask; overload; static;
  69. class function Join(const AProcs: array of TProc; APool: TThreadPool): ITask; overload; static;
  70. class function Join(const AProc1, AProc2: TProc): ITask; overload; static; inline;
  71. class function Join(const AProc1, AProc2: TProc; APool: TThreadPool): ITask; overload; static;
  72. end;

当Application空闲Idle时你要在UI线程勤做的事情:

function CheckSynchronize(Timeout: Integer = 0): Boolean;  //unit System.Classes;


转载:https://blog.csdn.net/pulledup/article/details/115438084
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场