LoadProgram()
LoadProgramPrio()
LoadCode()
UnloadCode()
ExecuteAsSubroutine()
ExecuteAsThread()
LoadProgram()
loads an executable file from disk and launches a new task which executes the code in the file.
Item LoadProgram(char *cmdLine);
argc
and argv
in the main()
function. The file name component of the command line specifies either a fully qualified pathname, or a pathname relative to the current directory.
The priority of the new task is the same as the priority of the current task. If the task should have a different priority, use the LoadProgramPrio()
function.
LoadProgramPrio()
is identical to LoadProgram()
except that it specifies a task priority for the new task.
Item LoadProgramPrio(char *cmdLine, int32 priority);
LoadProgram()
, the entire command line is passed to the new task as argc
and argv
in the main()
function. The file name component of the command line specifies either a fully qualified pathname, or a pathname relative to the current directory.
The priority
argument specifies the task priority for the new task. If you simply want the new task to have the same priority as the current task, use the LoadProgram()
function instead. Alternatively, passing a negative priority to this function will also give the new task the same priority as the current task. LoadProgram()
and LoadProgramPrio()
will set the current directory of the newly created task to the directory from which the executable was loaded.
LoadCode()
loads an executable file from disk into memory. Once loaded, the code can be spawned as a thread, or executed as a subroutine.
Err LoadCode(char *fileName, CodeHandle *code);
This function requires the name of the executable file to load, as well as a pointer to a CodeHandle
variable, where the handle for the loaded code will be stored.
Note: code
must point to a valid CodeHandle
variable, because LoadCode() uses this location to put a pointer to the loaded code.
ExecuteAsThread()
function or the ExecuteAsSubroutine()
function. If the loaded code is reentrant, the same loaded code can be spawned multiple times simultaneously as a thread.
ExecuteAsSubroutine()
executes a chunk of code that was previously loaded from disk using LoadCode()
.
int32 ExecuteAsSubroutine(CodeHandle code, int32 argc, char **argv);
The parameters in argc
and argv
are passed directly to the main()
entry point of the loaded code. The return value of this function is the value returned by main()
of the code being run.
The values you supply for argc
and argv
are irrelevant to this function. They are simply passed through to the loaded code. Therefore, their meaning must be agreed upon by the caller of this function, and by the loaded code.
ExecuteAsThread()
executes a chunk of code that was previously loaded from disk using LoadCode()
. This function executes code that will execute as a thread of the current task.
Item ExecuteAsThread(CodeHandle code, int32 argc, char **argv, char *threadName, int32 priority);
The argc
and argv
parameters are passed directly to the main()
entry point of the loaded code.The values you supply for argc
and argv
are irrelevant to this function. They are simply passed through to the loaded code. Therefore, their meaning must be agreed upon by the caller of this function, and by the loaded code. threadName
specifies the name of the thread. priority
specifies the priority the new thread should have. Providing a negative priority makes the thread inherit the priority of the current task or thread.
UnloadCode()
function. UnloadCode()
frees any resources allocated by LoadCode()
. Once UnloadCode()
has been called, the code handle supplied becomes invalid and cannot be used again.