Page 1 of 1

named threads

Posted: Mon Jun 13, 2011 6:47 am
by pete_jan
Have you thought about having names in the treads structure, so the thread info eg,

Code: Select all

addr   stack  prio refs     state   time
0x1c06 0x5b72   64    1   CURRENT      26
0x2342 0x2382    1    1     READY    3460
0x1e3c 0x1ec6    2    1     READY       0
0x1eee 0x1f68   64    1     WTSEM       2
0x1fa2 0x201c   64    1     WTSEM       0
0x2054 0x20ce   64    1     WTSEM     102
0x2108 0x219e   64    1     FINAL     269


Could also have a name attached?

This could be just a pointer in the thread structure that points to a string (which would be in ROM to save space).

So CreateThread would take another parameter which is a pointer to a string.

Re: named threads

Posted: Mon Jun 13, 2011 7:55 am
by Giovanni
Hi,

So far I've been reluctant to add this because the extra space required and the extra parameter that mostly would be used at debug time only.

Currently there is an alternate solution: in chconf.h it is possible to use the hook macro THREAD_EXT_FIELDS to add a "char *p_name" to the Thread structure, then use THREAD_EXT_INIT_HOOK() to initialize it to NULL by default.
Each thread could setup its own name using a macro, something like CH_THD_SET_NAME("myname") as very first instruction:

Code: Select all

#define CH_THD_SET_NAME(name) currp->p_name = (name)
#define CH_THD_GET_NAME() currp->p_name

msg_t my_thread(void *p) {

  CH_THD_SET_NAME("my_name");
  ...
}


This solution has also the advantage that can be implemented to be switched off transparently when not needed, the extra parameter would be there even if not used. Probably this should be added to the kernel permanently as a debug functionality.

Giovanni

Re: named threads

Posted: Mon Jun 13, 2011 9:12 am
by pete_jan
Thanks for the quick reply.

I thought there would be a way, and thought about using the THREAD_EXT_FIELDS.

Works for me.