Skip to content

Commit fa32671

Browse files
dcpleungcfriedt
authored andcommitted
samples: prod_consumer: don't reuse main stack for app_b
With demand paging, the main stack is not user mode capable and it would fail k_thread_user_mode_enter() under app_b_entry(). So create another thread and stack for app_b as this stack can be used in user mode. Signed-off-by: Daniel Leung <[email protected]>
1 parent 6a58c34 commit fa32671

File tree

1 file changed

+16
-5
lines changed
  • samples/userspace/prod_consumer/src

1 file changed

+16
-5
lines changed

samples/userspace/prod_consumer/src/main.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "app_b.h"
1818

1919
#define APP_A_STACKSIZE 2048
20+
#define APP_B_STACKSIZE 2048
2021

2122
LOG_MODULE_REGISTER(app_main);
2223

@@ -45,8 +46,13 @@ K_QUEUE_DEFINE(shared_queue_outgoing);
4546
struct k_thread app_a_thread;
4647
K_THREAD_STACK_DEFINE(app_a_stack, APP_A_STACKSIZE);
4748

49+
struct k_thread app_b_thread;
50+
K_THREAD_STACK_DEFINE(app_b_stack, APP_B_STACKSIZE);
51+
4852
void main(void)
4953
{
54+
k_tid_t thread_a, thread_b;
55+
5056
LOG_INF("APP A partition: %p %zu", (void *)app_a_partition.start,
5157
(size_t)app_a_partition.size);
5258
LOG_INF("Shared partition: %p %zu", (void *)shared_partition.start,
@@ -58,10 +64,15 @@ void main(void)
5864
sys_heap_init(&shared_pool, shared_pool_mem, HEAP_BYTES);
5965

6066
/* Spawn supervisor entry for application A */
61-
k_thread_create(&app_a_thread, app_a_stack, APP_A_STACKSIZE,
62-
app_a_entry, NULL, NULL, NULL,
63-
-1, K_INHERIT_PERMS, K_NO_WAIT);
67+
thread_a = k_thread_create(&app_a_thread, app_a_stack, APP_A_STACKSIZE,
68+
app_a_entry, NULL, NULL, NULL,
69+
-1, K_INHERIT_PERMS, K_NO_WAIT);
70+
71+
/* Spawn supervisor entry for application B */
72+
thread_b = k_thread_create(&app_b_thread, app_b_stack, APP_A_STACKSIZE,
73+
app_b_entry, NULL, NULL, NULL,
74+
-1, K_INHERIT_PERMS, K_NO_WAIT);
6475

65-
/* Re-use main for app B supervisor mode setup */
66-
app_b_entry(NULL, NULL, NULL);
76+
k_thread_join(thread_a, K_FOREVER);
77+
k_thread_join(thread_b, K_FOREVER);
6778
}

0 commit comments

Comments
 (0)