mthread_p mthr_create(unsigned stacksize, unsigned mode, start_func ufct, void *arg);
For the new thread a stack of size stacksize will be allocated. If stacksize is zero a default size will be chosen which can be adjusted by mthr_config(3). If stacksize is less than the minimum size configured for the system, the minimum stack size will be used. Be aware that there are no mechanisms to enlarge the stack once a thread has started. Moreover there is no hardware protection that ensures that no stack overflow occures. A stack overflow may crash the whole application.
The option mode controls which type of thread will be created and where the new thread will be enqueued:
start_func is the function that will be executed by the new thread. This function must be of the following type:
void *(*start_func)(void *arg)
Usually this function shouldn't return, but should be terminated by a call to mthr_exit(3). If it returns mthr_exit will be called implicitly, terminating the userlevel thread with exitvalue 0. The start function will be called with arg as the only argument.
#include <mthread.h> void *hello(void *arg) { printf("Hello! %s\n",(char *)arg); mthr_exit(0); } void main() { mthr_startup(); mthr_create(0,DETACHED | NODE_LOCAL, hello, "That's a userlevel thread."); mthr_exit(0); }