User Tools

Site Tools


start_return_new_execution_thread_.htm
Navigation:  Language Reference > 13 - Built-in Functions >====== START (return new execution thread) ====== Previous pageReturn to chapter overviewNext page

NewC7.jpg

START(procedure [, stack ] [, passed value ] )

blk2blue.jpg

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.

NewCNet.jpg

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

Example:

MAP

NewProc1  PROCEDURE

NewProc2  PROCEDURE(STRING)

NewProc3  PROCEDURE(STRING,STRING)

NewProc4  PROCEDURE(STRING,STRING,STRING)

END

MainWin APPLICATION('My Application'),SYSTEM,MAX,ICON('MyIcon.ICO'),STATUS |

       ,HVSCROLL,RESIZE

        MENUBAR

         MENU('&File'),USE(?FileMenu)

          ITEM('Selection &1…'),USE(?MenuSelection1)

          ITEM('Selection &2…'),USE(?MenuSelection2)

          ITEM('Selection &3…'),USE(?MenuSelection3)

          ITEM('Selection &4…'),USE(?MenuSelection4)

          ITEM('E&xit'),USE(?Exit)

         END

       END

       END

SaveThread1  LONG                 !Declare thread number save variables

SaveThread2  LONG

SaveThread3  LONG

SaveThread4  LONG

GroupName    GROUP

F1            STRING(30)

F2            LONG

            END

CODE

OPEN(MainWin)                    !Open the APPLICATION

ACCEPT

 CASE ACCEPTED()

 OF ?MenuSelection1

  !Start thread with 35K stack

  SaveThread1 = START(NewProc1,35000)

 OF ?MenuSelection2

  !Start thread, passing 1 parm

  SaveThread2 = START(NewProc2,35000,GroupName)

 OF ?MenuSelection3

  !Start thread, passing 2 parms

  SaveThread3 = START(NewProc3,35000,'X','21')

 OF ?MenuSelection4

  !Start a new thread

  SaveThread4 = START(NewProc4,35000,'X','21',GroupName)

 OF ?Exit

  RETURN

 END

END

NewProc2   PROCEDURE(MyGroup)

LocalGroup  GROUP(GroupName)      !Declare local group same as passed group

           END

CODE

LocalGroup = MyGroup             !Get the passed data

See Also:

ACCEPT

THREAD

SETTARGET

POST

start_return_new_execution_thread_.htm.txt · Last modified: 2021/04/15 15:57 by 127.0.0.1