Sign in Join
FPDoc Onlineexperiment

TThread class

In unit Classes

Abstract Thread class.

Declaration

pascal
TThread = class

Descends from it: TCompileWorkerThread TDaemonThread

Description

The TThread class encapsulates the native thread support of the operating system. To create a thread, declare a descendant of the TThread object and override the Execute method. In this method, the tthread's code should be executed. To run a thread, create an instance of the tthread descendant, and call it's execute method.

It is also possible to simply execute a method or static procedure in a thread using the ExecuteInThread class method.

See also

Properties

ReturnValueprotectedReturn value of the thread when it stops executing.
TerminatedprotectedIndicates whether the Terminatemethod was called by the user.
CurrentThreadpublicReturn current thread instance.
Currentpublic
ProcessorCountpublicReturn the processor count for this system.
IsSingleProcessorpublicIs the current system single processor or not.
FreeOnTerminatepublicIndicates whether the thread should free itself when it stops executing.
HandlepublicReturns the thread handle.
ExternalThreadpublicIs the thread instance an external thread ?
PrioritypublicReturns the thread priority.
SuspendedpublicIndicates whether the thread is suspended.
FinishedpublicHas the thread finished executing.
ThreadIDpublicReturns the thread ID.
FatalExceptionpublicException that occurred during thread execution.

Methods

DoTerminateprotectedTerminates the thread.
TerminatedSetprotected
ExecuteprotectedExecute method. Must be overridden in a descendant thread.
SynchronizeprotectedSynchronizes the thread by executing the method in the main thread.
QueueprotectedQueue a method for execution in the main thread.
ForceQueueprotectedAlways queue a method for execution in the main thread.
CreatepublicCreates a new thread.
DestroypublicDestroys the thread object.
CreateAnonymousThreadpublicExecute code in an anonymous thread.
NameThreadForDebuggingpublicSet a thread name.
SetReturnValuepublicSet return value of a thread.
CheckTerminatedpublicCheck if the current thread has finished executing.
RemoveQueuedEventspublicRemove methods scheduled for execution from queue.
SpinWaitpublicPrevent thread execution in a spin-wait loop.
SleeppublicPrevent thread execution.
YieldpublicYield execution to other threads.
GetSystemTimespublicReturn CPU stats.
GetCPUUsagepublic
GetTickCountpublicReturn tick count (32-bit).
GetTickCount64publicReturn tick count (64-bit).
ExecuteInThreadpublicExecute a method or static procedure in a thread.
AfterConstructionpublicCode to be executed after construction but before execute.
StartpublicStarts a thread that was created in a suspended state.
ResumepublicResumes the thread's execution. Deprecated, see TThread.Start.
SuspendpublicSuspends the thread's execution.
TerminatepublicSignals the thread it should terminate.
WaitForpublicWaits for the thread to terminate and returns the exit status.
CurrentIsMainpublic

Events

OnTerminatepublicEvent called when the thread terminates.

Fields

FThreadIDprotected

Types and constants

TSystemTimespublicRecord for returning processor usage.

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.