samples: synchronisation: set thread names
- Use new k_thread_name_set to set thread names. - Use board name in sample instead of architecture. Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
parent
739fd90127
commit
2f30c5dcb8
2 changed files with 17 additions and 4 deletions
|
|
@ -1 +1,3 @@
|
|||
CONFIG_STDOUT_CONSOLE=y
|
||||
# enable to use thread names
|
||||
#CONFIG_THREAD_NAME=y
|
||||
|
|
|
|||
|
|
@ -35,12 +35,21 @@
|
|||
void helloLoop(const char *my_name,
|
||||
struct k_sem *my_sem, struct k_sem *other_sem)
|
||||
{
|
||||
const char *tname;
|
||||
|
||||
while (1) {
|
||||
/* take my semaphore */
|
||||
k_sem_take(my_sem, K_FOREVER);
|
||||
|
||||
/* say "hello" */
|
||||
printk("%s: Hello World from %s!\n", my_name, CONFIG_ARCH);
|
||||
tname = k_thread_name_get(k_current_get());
|
||||
if (tname == NULL) {
|
||||
printk("%s: Hello World from %s!\n",
|
||||
my_name, CONFIG_BOARD);
|
||||
} else {
|
||||
printk("%s: Hello World from %s!\n",
|
||||
tname, CONFIG_BOARD);
|
||||
}
|
||||
|
||||
/* wait a while, then let other thread have a turn */
|
||||
k_sleep(SLEEPTIME);
|
||||
|
|
@ -78,13 +87,15 @@ void threadA(void *dummy1, void *dummy2, void *dummy3)
|
|||
ARG_UNUSED(dummy3);
|
||||
|
||||
/* spawn threadB */
|
||||
k_thread_create(&threadB_data, threadB_stack_area, STACKSIZE,
|
||||
threadB, NULL, NULL, NULL,
|
||||
k_tid_t tid = k_thread_create(&threadB_data, threadB_stack_area,
|
||||
STACKSIZE, threadB, NULL, NULL, NULL,
|
||||
PRIORITY, 0, K_NO_WAIT);
|
||||
|
||||
k_thread_name_set(tid, "thread_b");
|
||||
|
||||
/* invoke routine to ping-pong hello messages with threadB */
|
||||
helloLoop(__func__, &threadA_sem, &threadB_sem);
|
||||
}
|
||||
|
||||
K_THREAD_DEFINE(threadA_id, STACKSIZE, threadA, NULL, NULL, NULL,
|
||||
K_THREAD_DEFINE(thread_a, STACKSIZE, threadA, NULL, NULL, NULL,
|
||||
PRIORITY, 0, K_NO_WAIT);
|
||||
|
|
|
|||
Loading…
Reference in a new issue