THREAD_CREATE
Purpose
thread_create creates a new thread.
Synopsis
#include <types.h>
#include <stub.h>
int thread_create(Capability
*task, int (*entry)(), Word state, Capability *thread);
Parameters
-
task: capability for the task
on which the thread is to be created;
-
entry: a pointer to the function
where the thread should start its execution;
-
state: the thread initial state;
-
thread: the capability for the
created thread.
Description
thread_create creates a new thread
over the task specified by task. The created thread is associated
to a new owner capability that is returned through thread.
Thread creation in Aboelha is very flexible.
A new thread can be created to execute any function on the task's code,
i. e., the programmer, differently from Unix, does not need to dispatch
the thread. This is done by supplying the thread entry point through entry.
The first thread over a task is usually created by the loader
and has its entry point set to the beginning of the task's code, i.e. .,
0 (not main as one could expect).
It is not always desirable to create a new
thread that starts up running immediately. Some times it is necessary,
for instance, to set up a thread mash before starting the threads.
In order to support these cases, it is allowed to the user to specify the
thread's creation state. The following states are allowed:
-
READY: the created thread is inserted
in the Ready Queue and the thread is able to run as soon as its priority
becomes the highest;
-
SUSPENDED: the created thread is
inserted in the Suspended Queue and is not able to be scheduled until thread_resume
is applied on it.
The priority information (minimum, maximum
and current priority) for the new thread is inherited from the creator
thread and can be altered by calling thread_priority.
Each new thread has its own stack. At present,
the stack is created empty and there are no means by which one could pass
parameters through it. Note that this is a stub limitation. If you need
to pass parameters to the created thread at creation time you should refrain
from using this stub and invoke the respective kernel methods.
Return Values
On success, thread_create returns 0
and thread contains a valid owner capability for the created thread.
On fail, thread_create returns a negative
value indicating one of the following errors:
See Also
thread_destroy,
thread_status, thread_self,
thread_exit, thread_wait,
thread_priority, thread_sleep,
thread_yield, thread_suspend,
thread_resume,