|Navigation: Language Reference > 13 - Built-in Functions >====== START (return new execution thread) ======|
START(procedure [, stack ] [, passed value ] )
|START||Begins a new execution thread.|
|procedure||The label of the first PROCEDURE to call on the new execution thread. This may not be an overloaded procedure.|
|stack||An integer constant or variable containing the size of the stack to allocate to the new execution thread. If omitted, the default stack is 20,000 bytes.|
|passed value||A string constant, variable, or expression containing the value to pass as a parameter to the procedure. There may be up to three passed values listed.|
The START procedure begins a new execution thread, calling the procedure and returning the number assigned to the new thread. The returned thread number is used by procedures and built-in procedures whose action may be performed on any execution thread (e.g., SETTARGET). The maximum number of simultaneously available execution threads in a single application is theoretically unlimited. However, the word “unlimited” means that limits are applied not by the Clarion Runtime Library, but by the Operating System's environment settings, i.e., limited to the amount of virtual memory available for the process, or limited number of threads in the system, or limited number of windows (including controls) that can be opened simultaneously in the process, etc.
Code execution in the launching thread immediately continues with the next statement following the START and continues until an ACCEPT statement executes. Once the launching thread executes ACCEPT, the launched procedure begins executing its code in its new thread, retaining control until it executes an ACCEPT.
The procedure may be prototyped to receive up to three STRING or GROUP parameters (passed by value) which may not be omitted. The values to pass to the procedure are listed as the passed values parameters to the START statement, and not in a parameter list atached to the procedure within the START statement. The procedure may not be an overloaded procedure.
The first execution thread in any program is the main program code, which is always numbered one (1). Therefore, the lowest value START can return is two (2), when the first START procedure is executed in a program. START may return zero (0), which indicates failure to open the thread. This can occur by running out of memory, or by starting a thread when the system is modal.
The stack parameter has no meaning in the Clarion# environment and is ignored if present.
In Clarion#, the START function has the following form that supports the use of an arbitrary numbers of parameters:
START( procedure, stack, PARAMS array[ ] arrayname)
See PARAMS for more information.
Return Data Type: SIGNED
MainWin APPLICATION('My Application'),SYSTEM,MAX,ICON('MyIcon.ICO'),STATUS |
SaveThread1 LONG !Declare thread number save variables
OPEN(MainWin) !Open the APPLICATION
!Start thread with 35K stack
SaveThread1 = START(NewProc1,35000)
!Start thread, passing 1 parm
SaveThread2 = START(NewProc2,35000,GroupName)
!Start thread, passing 2 parms
SaveThread3 = START(NewProc3,35000,'X','21')
!Start a new thread
SaveThread4 = START(NewProc4,35000,'X','21',GroupName)
LocalGroup GROUP(GroupName) !Declare local group same as passed group
LocalGroup = MyGroup !Get the passed data