Creates a new context and a thread for the context.
#include <nks/thread.h> int NXThreadCreateSx ( void (*start_routine)(void *arg), void *arg, unsigned long thread_flags, NXContext_t *ctx, NXThreadId_t *thr);
Points to the function to be executed. The arg parameter specifies the argument to be passed to the start_routine.
Points to the parameter for the start_routine.
Specifies the attributes for the new thread. Can be zero or a bitwise OR of the following:
(OUT) Points to a context structure specifying the run-time state of the thread.
(OUT) Points to the new thread's identifier. If not NULL, the ID of the newly created thread is returned in the location pointed to by thread_id.
If successful, returns 0; otherwise, returns a nonzero error code:
The NXThreadCreateSx function encodes calls to both NXContextAlloc and NXThreadCreate for use when an abbreviation of the two is useful in creating an application thread. The context is created with the following characteristics:
Medium priority (NX_PRIO_MED)
Normal context (NX_CTX_NORMAL)
System-provided stack size
The priority can be changed with NXThreadSetPriority; the stack size and context type cannot be changed.
When a thread (daemon or application) is created with the NX_THR_BIND_CTX flag, the thread is permanently bound to the context that is passed in. Such a thread cannot switch the contexts hosted by it by calling NXThreadSwapContext. The context hosted by such a thread is automatically destroyed when the thread terminates.
When thread that is created without the NX_THR_BIND_CTX flag terminates, the context hosted by it is not automatically destroyed. Application threads created this way are not bound to the passed in context and can be switched to a different context by calling NXThreadSwapContext. Because the contexts hosted by the threads created this way are not automatically destroyed when the thread terminates, the application must manage the context and free it appropriately.
#include <stdio.h> #include <nks/thread.h> void start( void *arg ) { printf(“This is printed by the new, detached thread!\n”); printf(“The value printed here should be 99: %d\n”, (int) arg); } int print99foo( NXThreadId_t *id ) { int err; NXContext_t ctx; NXThreadId_t thr; err = NXThreadCreateSx(start, (void *) 99, NX_THR_DETACHED, &ctx, &thr); if (err) return err; *id = thr; return 0; }