Show: Delphi C++
Display Preferences

System.BeginThread

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

function BeginThread(SecurityAttributes: Pointer; StackSize: LongWord; ThreadFunc: TThreadFunc; Parameter: Pointer; CreationFlags: LongWord; var ThreadId: TThreadID): THandle;

C++

extern DELPHI_PACKAGE NativeUInt __fastcall BeginThread(void * SecurityAttributes, unsigned StackSize, TThreadFunc ThreadFunc, void * Parameter, unsigned CreationFlags, unsigned &ThreadId);

Properties

Type Visibility Source Unit Parent
function public
System.pas
System.hpp
System System

Description

Spawns a separate thread of execution.

Use this routine or a TThread object to spawn separate threads of execution. BeginThread spawns a new thread of execution and sets the global IsMultiThread variable, thereby making the heap thread-safe.

ThreadFunc is the thread function. This is the code that executes in the new thread of execution. ThreadFunc should handle all of its own exceptions. However, because BeginThread sets up an execution frame, the system's default exception handler will catch any exceptions that escape ThreadFunc.

Parameter points to a single 32-bit parameter that is passed, uninterpreted, to ThreadFunc.

ThreadId returns the unique identifier for the new thread. This ID appears in the Thread Status box of the debugger.

SecurityAttributes is a pointer to a Windows SecurityAttributes record (structure). For details on security attributes, see the Microsoft documentation.

StackSize is the size of the stack reserved for the new thread when CreationFlags includes STACK_SIZE_IS_A_RESERVATION. Otherwise, this parameter is ignored.

CreationFlags is a set of bits or'ed together that are drawn from the following:


Value Meaning

CREATE_SUSPENDED

The thread is created in a suspended state and does not run until the Windows API ResumeThread function is called. If this flag is not included, the new thread starts running as soon as it is created.

STACK_SIZE_PARAM_IS_A_RESERVATION

The StackSize parameter specifies the stack size for the thread. If this flag is not included, the new thread is assigned a default stack size by the linker.


BeginThread returns the Windows thread handle. A return value of 0 indicates failure.

Attribute is a structure containing information about the thread such as its priority, its schedule policy, and its stack size.


See Also

Personal tools
In Other Languages
Previous Versions
Assistance