From c514fde867864210e8e451638b7249cefa3ea5fc Mon Sep 17 00:00:00 2001 From: vicLin8712 Date: Sat, 22 Nov 2025 12:40:39 +0800 Subject: [PATCH] Fix task ID inconsistency in suspend path The introduction of the logger task in previous commits changed the task creation order, which caused inconsistencies in fixed task ID assignments. This commit binds the task ID directly from the creation parameter, ensuring deterministic and correct ID assignment regardless of task creation order. --- app/suspend.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/suspend.c b/app/suspend.c index 653ef68..36a64b3 100644 --- a/app/suspend.c +++ b/app/suspend.c @@ -1,5 +1,7 @@ #include +int32_t task0_id, task1_id, task2_id; + void task2(void) { int32_t cnt = 0; @@ -16,14 +18,14 @@ void task1(void) while (1) { printf("[task %d %ld]\n", mo_task_id(), cnt++); if (cnt == 2000) { - val = mo_task_resume(2); + val = mo_task_resume(task2_id); if (val == 0) printf("TASK 2 RESUMED!\n"); else printf("FAILED TO RESUME TASK 2\n"); } if (cnt == 6000) { - val = mo_task_resume(0); + val = mo_task_resume(task0_id); if (val == 0) printf("TASK 0 RESUMED!\n"); else @@ -39,7 +41,7 @@ void task0(void) while (1) { printf("[task %d %ld]\n", mo_task_id(), cnt++); if (cnt == 1000) { - val = mo_task_suspend(2); + val = mo_task_suspend(task2_id); if (val == 0) printf("TASK 2 SUSPENDED!\n"); else @@ -54,9 +56,9 @@ void task0(void) int32_t app_main(void) { - mo_task_spawn(task0, DEFAULT_STACK_SIZE); - mo_task_spawn(task1, DEFAULT_STACK_SIZE); - mo_task_spawn(task2, DEFAULT_STACK_SIZE); + task0_id = mo_task_spawn(task0, DEFAULT_STACK_SIZE); + task1_id = mo_task_spawn(task1, DEFAULT_STACK_SIZE); + task2_id = mo_task_spawn(task2, DEFAULT_STACK_SIZE); /* preemptive mode */ return 1;