RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
System.BeginThread Function

Spawns a separate thread of execution.

Pascal
function BeginThread(SecurityAttributes: Pointer; StackSize: LongWord; ThreadFunc: TThreadFunc; Parameter: Pointer; CreationFlags: LongWord; var ThreadId: LongWord): Integer;
C++
int BeginThread(void * SecurityAttributes, LongWord StackSize, TThreadFunc ThreadFunc, void * Parameter, LongWord CreationFlags, LongWord ThreadId);

System

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.  

On Windows, 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. 

On Linux, Begin Thread returns 0 if the thread is successfully spawned, an error code otherwise. 

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!