[okl4-developer] Creating threads

Joshua Root jmr at cse.unsw.edu.au
Wed Aug 6 00:12:36 EST 2008


Guillaume PETITJEAN wrote:
> How do you set the name of a thread in OKL4 and is it possible ?

For debugging purposes? Use L4_KDB_SetThreadName().

> When using thread_create_simple(), how is the stack created (where ?
> size ?)  ?
> I guess that if I use  thread_create_simple() I don't need to use
> thread_start() right ?

 From libs/iguana/src/thread_create_simple.c:

thread_ref_t
thread_create_simple(void (*fn) (void *), void *arg, int priority)
{
     void **stack_top;
     L4_ThreadId_t ignore;
     thread_ref_t thread;
     memsection_ref_t memref;

#define STACK_SIZE 0x1000
     memref = memsection_create(STACK_SIZE, (void *)&stack_top);
     if (memref == 0)
         return 0;
     stack_top = (void **)((uintptr_t)stack_top + STACK_SIZE);
     stack_top--;
     *stack_top = (void *)fn;
     stack_top--;
     *stack_top = arg;
     thread = thread_create_priority(priority, &ignore);
     thread_start(thread, (uintptr_t)__thread_stub, (uintptr_t)stack_top);
     return thread;
}

The memsecton_create() call simply allocates some memory from the 
default virtual and physical pools.

> Is it a good idea to use this fucntion or is it better to do like in
> thread_tests.c :
> 1) thread_create
> 2) create stack by hand
> 3) thread_start
> which is really not convenient...

If you are satisfied with the policies used by thread_create_simple, 
then of course you should use it rather than write your own version.

- Josh



More information about the Developer mailing list