thread - runnable / computation entity
The thread object is the construct that represents a time-shared CPU execution context. Thread objects live associated to a particular Process Object which provides the memory and the handles to other objects necessary for I/O and computation.
Threads are created by calling
zx_thread_create(), but only start executing when either
zx_process_start() are called. Both syscalls take as an argument the entrypoint of the initial routine to execute.
The thread passed to
zx_process_start() should be the first thread to start execution on a process.
A thread terminates execution:
zx_task_kill()with the thread's handle
Returning from the entrypoint routine does not terminate execution. The last action of the entrypoint should be to call
zx_thread_exit() or one of the above mentioned
Closing the last handle to a thread does not terminate execution. In order to forcefully kill a thread for which there is no available handle, use
zx_object_get_child() to obtain a handle to the thread. This method is strongly discouraged. Killing a thread that is executing might leave the process in a corrupt state.
Fuchsia native threads are always detached. That is, there is no join() operation needed to do a clean termination. However, some runtimes above the kernel, such as C11 or POSIX might require threads to be joined.
zx_thread_create()- create a new thread within a process
zx_thread_exit()- exit the current thread
zx_thread_read_state()- read register state from a thread
zx_thread_start()- cause a new thread to start executing
zx_thread_write_state()- modify register state of a thread
zx_task_bind_exception_port()- attach an exception port to a task
zx_task_kill()- cause a task to stop running