Skip to content

Commit ac6d1e2

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 ac6d1e2

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/utest/smp/smp_thread_preemption_tc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
* @note Create multiple threads, low-priority threads run first,
1818
* high-priority threads preempt low-priority threads, and
1919
* print the current status of each core in the thread's entry function.
20+
*
2021
*/
2122

2223
#define THREAD_PRIORITY_HIGH 21
2324
#define THREAD_PRIORITY_LOW 30
2425
#define THREAD_STACK_SIZE UTEST_THR_STACK_SIZE
2526

2627
static rt_thread_t threads[2];
28+
static volatile rt_uint8_t finish_flag = 0;
2729
static struct rt_spinlock lock;
2830

2931
/* High Priority Thread */
@@ -35,6 +37,7 @@ static void thread_high_entry(void *parameter)
3537
extern long list_thread(void);
3638
list_thread();
3739
rt_spin_unlock(&lock);
40+
finish_flag = 1;
3841
}
3942

4043
/* Low Priority Thread */
@@ -46,6 +49,7 @@ static void thread_low_entry(void *parameter)
4649
extern long list_thread(void);
4750
list_thread();
4851
rt_spin_unlock(&lock);
52+
while (!finish_flag);
4953
}
5054

5155
static void thread_preemptions_tc(void)
@@ -72,6 +76,7 @@ static void thread_preemptions_tc(void)
7276
static rt_err_t utest_tc_init(void)
7377
{
7478
rt_spin_lock_init(&lock);
79+
finish_flag = 0;
7580
return RT_EOK;
7681
}
7782

0 commit comments

Comments
 (0)