Thread Programmierung unter Windows mit Delphi
1 Thread Programmierung unter Windows mit Delphi Michael Puff
oder dem von ExitThread oder TerminateThread festgelegten Wert, ... Mit dem Gegenstück zu SetThreadPriority, GetThreadPriority, lässt sich die aktuelle ...
https://docwiki.embarcadero.com/Libraries/Sydney/en/System.Classes.TThread.Terminate
https://stackoverflow.com/questions/12475395/delphi-threading
Thread Delphi SetThreadPriority GetThreadPriority SetThreadPriorityBoost GetThreadPriorityBoost ExitThread TerminateThread GetExitCodeThread CloseHandle
SwitchToThread 切換到另一個可排程執行緒 CreateThread 建立執行緒 CreateRemoteThread 建立遠端執行緒 GetCurrentThread 獲取執行緒控制代碼 GetCurrentThreadId 獲取執行緒ID OpenThread 開啟一個現有執行緒物件 SetThreadPriority 設定執行緒優先順序 GetThreadPriority 獲取執行緒優先順序 SetThreadPriorityBoost 設定開關–系統動態提升該執行緒的優先順序 GetThreadPriorityBoost 獲取~開關 ExitThread 線上程的執行過程中終止 TerminateThread 線上程的外面終止 GetExitCodeThread 獲取一個已中止執行緒的退出程式碼 SuspendThread 暫停執行緒 ResumeThread 恢復執行緒 SetThreadStackGuarantee 要求系統在丟擲EXCEPTION_STACK_OVERFLOW異常的時候,保證仍然有指定大小的空閒區可以用 WaitForSingleObject 阻塞,直到等到訊號 CloseHandle 關閉控制代碼
Yield SpinWait Sleep SwitchToThread SuspendThread ResumeThread
System.Threading mscorlib.dll, netstandard.dll Thread.dll Thread.Interrupt
https://coderoad.ru/12751031/%D0%9A%D0%B0%D0%BA%D0%BE%D0%B9-%D0%BC%D0%B5%D1%82%D0%BE%D0%B4-%D0%BE%D0%B6%D0%B8%D0%B4%D0%B0%D0%BD%D0%B8%D1%8F-%D0%B2%D1%8B%D0%B7%D0%B2%D0%B0%D1%82%D1%8C-%D0%B2-%D0%B1%D0%B5%D1%81%D0%BA%D0%BE%D0%BD%D0%B5%D1%87%D0%BD%D0%BE%D0%BC-%D0%BF%D0%BE%D1%82%D0%BE%D0%BA%D0%B5-%D0%BE%D0%B6%D0%B8%D0%B4%D0%B0%D0%BD%D0%B8%D1%8F-%D0%B4%D0%BB%D1%8F-Delphi-XE2
unit ThreadPool;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, contnrs, syncobjs;
type
TpooledTask=class(TObject)
private
FonComplete:TNotifyEvent;
protected
Fparam:TObject;
procedure execute; virtual; abstract;
public
constructor create(onComplete:TNotifyEvent;param:TObject);
end;
TThreadPool=class(TObjectQueue)
private
access:TcriticalSection;
taskCounter:THandle;
threadCount:integer;
public
constructor create(initThreads:integer);
procedure addTask(aTask:TpooledTask);
end;
TpoolThread=class(Tthread)
private
FmyPool:TThreadPool;
protected
procedure Execute; override;
public
constructor create(pool:TThreadPool);
end;
implementation
{ TpooledTask }
constructor TpooledTask.create(onComplete: TNotifyEvent; param: TObject);
begin
FonComplete:=onComplete;
Fparam:=param;
end;
{ TThreadPool }
procedure TThreadPool.addTask(aTask: TpooledTask);
begin
access.acquire;
try
push(aTask);
finally
access.release;
end;
releaseSemaphore(taskCounter,1,nil); // release one unit to semaphore
end;
constructor TThreadPool.create(initThreads: integer);
begin
inherited create;
access:=TcriticalSection.create;
taskCounter:=createSemaphore(nil,0,maxInt,'');
while(threadCount<initThreads) do
begin
TpoolThread.create(self);
inc(threadCount);
end;
end;
{ TpoolThread }
constructor TpoolThread.create(pool: TThreadPool);
begin
inherited create(true);
FmyPool:=pool;
FreeOnTerminate:=true;
resume;
end;
procedure TpoolThread.execute;
var thisTask:TpooledTask;
begin
while (WAIT_OBJECT_0=waitForSingleObject(FmyPool.taskCounter,INFINITE)) do
begin
FmyPool.access.acquire;
try
thisTask:=TpooledTask(FmyPool.pop);
finally
FmyPool.access.release;
end;
thisTask.execute;
if assigned(thisTask.FonComplete) then thisTask.FonComplete(thisTask);
end;
end;
end.
https://docwiki.embarcadero.com/Libraries/Sydney/en/System.Threading.TTask
System.Threading
TTask
TParallel
TFuture
TThreadPool
TWorkStealingQueue
https://docwiki.embarcadero.com/Libraries/Sydney/en/System.SyncObjs
SyncObjs
TMutex
TCriticalSection
TSemaphore
TEvent
TThread
THandleObject
TConditionVariableCS
TConditionVariableMutex
TConditionVariableHelper
TCriticalSectionHelper
https://www.modernescpp.com/index.php/tasks
https://blog.marcocantu.com/blog/2017-november-explaining-tasks-ppl-too-many.html
https://www.embarcaderoacademy.com/p/anonymous-methods-in-delphi/
https://www.embarcaderoacademy.com/p/master-modern-delphi-language-techniques
https://docwiki.embarcadero.com/RADStudio/Sydney/en/Using_Critical_Sections
https://docwiki.embarcadero.com/RADStudio/Sydney/en/Using_Critical_Sections
https://docwiki.embarcadero.com/RADStudio/Sydney/en/Locking_Objects
https://docwiki.embarcadero.com/RADStudio/Sydney/en/Using_the_Main_VCL_Thread
https://docwiki.embarcadero.com/RADStudio/Sydney/en/Using_the_Multi-read_Exclusive-write_Synchronizer
https://www.informit.com/articles/article.aspx?p=30382&seqNum=6
https://github.com/pocoproject/poco
https://docs.microsoft.com/zh-tw/dotnet/standard/threading/pausing-and-resuming-threads
https://docwiki.embarcadero.com/RADStudio/Sydney/en/Service_Threads
SparkyThread.Suspend; SparkyThread.Resume;
https://docwiki.embarcadero.com/Libraries/Alexandria/en/Vcl.SvcMgr.TService.OnExecute
https://docwiki.embarcadero.com/Libraries/Sydney/en/System.SyncObjs
https://stackoverflow.com/questions/67246114/delphi-what-happens-when-the-app-terminates-while-a-thread-is-waiting-on-an-even
https://www.freepascal.org/docs-html/rtl/classes/tthread.html
delphi System Threading Thread.Interrupt AutoResetEvent Wait Set
kernel32 Thread Scheduling Yield setThreadPriority SetThreadPriority(pi.hThread, THREAD_PRIORITY_IDLE); ResumeThread(pi.hThread);
https://docwiki.embarcadero.com/CodeExamples/Sydney/en/TThreadYield_(Delphi)
沒有留言:
張貼留言