CreateThread

Creates a thread.

Synopsis

Item CreateThread( const char *name, uint8 pri, void (*code) (),int32 stacksize )

Description

This procedure creates a thread. The resulting thread belongs to the calling task.

Arguments

name
The name of the thread to be created (see "Notes").
pri
The priority of the thread. This can be a value from 11 to 199 (0 to 10 and 200 to 255 can only be assigned by system software). A larger number specifies a higher priority. For all tasks, including threads, the highest priority task - if there is only one task with that priority - is always the task that is executed. If more than one task in the ready queue has the highest priority, the kernel divides the available CPU time among the tasks by providing each task with a time quantum.
code
A pointer to the code that the thread executes.
stacksize
The size of the thread's stack, in bytes (see "Notes").

Return Value

The procedure returns the item number of the thread or an error code if an error occurs.

Implementation

Convenience call implemented in clib.lib V20.

Associated Files

task.h
ANSI C Prototype
clib.lib
ARM Link Library

Notes

There is no default size for a thread's stack. To avoid stack overflow errors, the stack must be large enough to handle any possible uses. One way to find the proper stack size for a thread is to start with a very large stack, reduce its size until a stack overflow occurs, and then double its size.

When you no longer need a thread, use DeleteThread() to delete it. Alternatively, the thread can return or call exit().

You can use FindTask() to find a thread by name. When naming threads, you should assign unique names whenever possible.

See Also

DeleteThread(), exit()