Skip to content

Commit c514fde

Browse files
committed
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.
1 parent 3d94a32 commit c514fde

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

app/suspend.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <linmo.h>
22

3+
int32_t task0_id, task1_id, task2_id;
4+
35
void task2(void)
46
{
57
int32_t cnt = 0;
@@ -16,14 +18,14 @@ void task1(void)
1618
while (1) {
1719
printf("[task %d %ld]\n", mo_task_id(), cnt++);
1820
if (cnt == 2000) {
19-
val = mo_task_resume(2);
21+
val = mo_task_resume(task2_id);
2022
if (val == 0)
2123
printf("TASK 2 RESUMED!\n");
2224
else
2325
printf("FAILED TO RESUME TASK 2\n");
2426
}
2527
if (cnt == 6000) {
26-
val = mo_task_resume(0);
28+
val = mo_task_resume(task0_id);
2729
if (val == 0)
2830
printf("TASK 0 RESUMED!\n");
2931
else
@@ -39,7 +41,7 @@ void task0(void)
3941
while (1) {
4042
printf("[task %d %ld]\n", mo_task_id(), cnt++);
4143
if (cnt == 1000) {
42-
val = mo_task_suspend(2);
44+
val = mo_task_suspend(task2_id);
4345
if (val == 0)
4446
printf("TASK 2 SUSPENDED!\n");
4547
else
@@ -54,9 +56,9 @@ void task0(void)
5456

5557
int32_t app_main(void)
5658
{
57-
mo_task_spawn(task0, DEFAULT_STACK_SIZE);
58-
mo_task_spawn(task1, DEFAULT_STACK_SIZE);
59-
mo_task_spawn(task2, DEFAULT_STACK_SIZE);
59+
task0_id = mo_task_spawn(task0, DEFAULT_STACK_SIZE);
60+
task1_id = mo_task_spawn(task1, DEFAULT_STACK_SIZE);
61+
task2_id = mo_task_spawn(task2, DEFAULT_STACK_SIZE);
6062

6163
/* preemptive mode */
6264
return 1;

0 commit comments

Comments
 (0)