System.Classes.TThread
Delphi
TThread = class
C++
class PASCALIMPLEMENTATION TThread : public System::TObject
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
class | public | System.Classes.pas System.Classes.hpp |
System.Classes | System.Classes |
Description
TThread is an abstract class that enables creation of separate threads of execution in an application.
Create a descendant of TThread to represent an execution thread in a multithreaded application. Each new instance of a TThread descendant is a new thread of execution. Multiple instances of a TThread derived class make an application multithreaded.
When an application is run, it is loaded into memory ready for execution. At this point it becomes a process containing one or more threads that contain the data, code and other system resources for the program. A thread executes one part of an application and is allocated CPU time by the operating system. All threads of a process share the same address space and can access the process's global variables.
Use threads to improve application performance by:
- Managing input from several communication devices.
- Distinguishing among tasks of varying priority. For example, a high priority thread handles time-critical tasks, and a low priority thread performs other tasks.
Following are issues and recommendations to be aware of when using threads:
- Keeping track of too many threads consumes CPU time; the recommended limit is 16 active threads per process on single processor systems.
- When multiple threads update the same resources, they must be synchronized to avoid conflicts.
- Most methods that access an object and update a form must only be called from within the main thread or use a synchronization object such as TMultiReadExclusiveWriteSynchronizer.
Define the thread object's Execute method by inserting the code that should execute when the thread is executed.
See Also
- See the Threads demo description at Freezing and Thawing Threads in the Debugger