Check for the same errors that pthread_create does. If an error occurs set errno to the symbolic integer and return -1.
- Check pointer to caller's uthread_id_t is not NULL. (E.g. use assert()
- Check priority is valid. If not set errno to EINVAL and return -1.
- The uthread_alloc function (you implement) should be called to
get an id for the uthread to be created. If no free entry in the
uthreads table, set errno to EAGAIN and return -1.
Note that errno is redefined so that it is thread specific. When a thread is the currently executing thread, errno is the member in that thread's uthreads entry.
Create a stack for the new thread and set this member in this thread's uthreads table entry. You can use the alloc_stack() function. It allocates a stack of size UTH_STACK_SIZE (64k bytes). errno = EAGAIN if alloc_stack() fails (returns NULL).
- Create the context for this thread and set its ut_ctx entry in the uthreads table. Use the uthread_makecontext function.