# thread.h Threading infrastructure. # `thread_T` - struct | Name | Type | Description | |-------------|--------------|--------------------------------------------------------------------------------------------------| | state | cpu_state_T* | The last saved state of the thread ( -> _context switching_(reference needed)) | | cpu_time | uint64_t | The amount of cpu time the thread had. (currently the amount of context switches the thread had) | | stack | void* | The bottom of the threads stack | | stack_size | uint32_t | The size of the threads stack (in bytes) | | process | process_T* | The process, to which the thread belongs to | | global_prev | thread_T* | The previous thread in the scheduling queue (**should only be accessed by the scheduler!**) | | global_next | thread_T* | The next thread in the scheduling queue (**should only be accessed by the scheduler!**) | | local_prev | thread_T* | The previous thread of _process_ (**should only be accessed by the scheduler!**) | | local_next | thread_T* | The next thread of _process_ (**should only be accessed by the scheduler!**) | | local_id | uint32_t | The threads id in its process | # `thread_spawn(function)` - function (thread_T*) Allocates a thread_T and registers it in the scheduler. The thread starts execution at **_function_**. The for the thread allocated stack has a size of 16 KB (4 Pages). The thread still needs to be started with thread_start(). Returns a pointer to the created thread. # `thread_spawn_from_state(state)` - function (thread_T*) Allocates a thread_T and registers it in the scheduler. The threads' _cpu_state_ is copied from **_state_**. This won't allocate a stack for the stack. The thread still needs to be started with thread_start(). Returns a pointer to the created thread. This function should be avoided. # `thread_start(thread)` - function (void) Starts/unpauses **_thread_**. # `thread_pause(thread)` - function (void) Pauses **_thread_**. # `thread_kill(thread)` - function (void) Kills **_thread_**. The threads stack and thread_T structure will be freed.