Skip to content

Commit 05846c6

Browse files
committed
[utest]:Modify the execution logic of smp_thread_preemptions
Currently, the print information of this test case fails to demonstrate that the high-priority thread has preempted the low-priority thread. This is because when the high-priority thread prints the thread list, there is no information about the low-priority thread (tlow), as tlow has already completed execution and been destroyed. Therefore, the current execution logic cannot confirm the successful completion of the preemption operation. Solution: After the low-priority thread (tlow) releases the lock, add a busy-wait loop while(!finish_flag);. At this point, when the high-priority thread (thigh) prints the thread list information, tlow can be observed in the ready state, indicating that it has been preempted by thigh. Signed-off-by: Mengchen Teng <[email protected]>
1 parent 39a52cd commit 05846c6

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/utest/smp/smp_thread_preemption_tc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#define THREAD_STACK_SIZE UTEST_THR_STACK_SIZE
2525

2626
static rt_thread_t threads[2];
27+
static rt_uint8_t finish_flag = 0;
2728
static struct rt_spinlock lock;
2829

2930
/* High Priority Thread */
@@ -35,6 +36,7 @@ static void thread_high_entry(void *parameter)
3536
extern long list_thread(void);
3637
list_thread();
3738
rt_spin_unlock(&lock);
39+
finish_flag = 1;
3840
}
3941

4042
/* Low Priority Thread */
@@ -46,6 +48,7 @@ static void thread_low_entry(void *parameter)
4648
extern long list_thread(void);
4749
list_thread();
4850
rt_spin_unlock(&lock);
51+
while(!finish_flag);
4952
}
5053

5154
static void thread_preemptions_tc(void)
@@ -72,6 +75,7 @@ static void thread_preemptions_tc(void)
7275
static rt_err_t utest_tc_init(void)
7376
{
7477
rt_spin_lock_init(&lock);
78+
finish_flag = 0;
7579
return RT_EOK;
7680
}
7781

0 commit comments

Comments
 (0)