Next: , Up: Thread Interface


7.1.1 Thread Creation

— Function: kern_return_t thread_create (task_t parent_task, thread_t *child_thread)

The function thread_create creates a new thread within the task specified by parent_task. The new thread has no processor state, and has a suspend count of 1. To get a new thread to run, first thread_create is called to get the new thread's identifier, (child_thread). Then thread_set_state is called to set a processor state, and finally thread_resume is called to get the thread scheduled to execute.

When the thread is created send rights to its thread kernel port are given to it and returned to the caller in child_thread. The new thread's exception port is set to MACH_PORT_NULL.

The function returns KERN_SUCCESS if a new thread has been created, KERN_INVALID_ARGUMENT if parent_task is not a valid task and KERN_RESOURCE_SHORTAGE if some critical kernel resource is not available.