From 21834bf76ef335ef622dec38e4a8b3c717a5e146 Mon Sep 17 00:00:00 2001 From: Yunlk <103742015+Yunlk@users.noreply.github.com> Date: Fri, 13 Nov 2026 09:37:00 +0800 Subject: [utest][atomic] release worker threads and semaphore between runs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在每轮原子操作测试结束后让出执行机会并删除信号量,避免重复运行时累积测试资源。 --- src/utest/atomic_tc.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src') diff --git a/src/utest/atomic_tc.c b/src/utest/atomic_tc.c index 9336f79243..2b32f38b47 100644 --- a/src/utest/atomic_tc.c +++ b/src/utest/atomic_tc.c @@ -181,6 +181,26 @@ static void test_atomic_add(void) } i = rt_atomic_load(&count); uassert_true(i == 3000000); + + /* + * The three workers exit right after releasing the semaphore, so their TCB + * and stack are only released once rt_defunct_execute() runs - and that runs + * in the idle thread, which never gets scheduled while this testcase keeps a + * runnable thread around. Without the yield below, every run of this testcase + * leaves three threads allocated: running it repeatedly in one boot grows the + * thread list 3 -> 6 -> 9 and the used heap by 3 * (stack + TCB) per run + * (measured 12952 bytes with UTEST_THR_STACK_SIZE = 4096 and 25240 with 8192, + * both of which reduce to an rt_thread of about 221 bytes). + * + * rt_thread_mdelay() suspends this thread for a tick and reschedules, so the + * CPU is handed to whatever else is ready - the idle thread included - and the + * defunct queue gets processed. It does not wait for the idle thread + * specifically; it only gives up the CPU, which is all that is needed here. + * Same convention as hooklist_tc.c, which waits for the defunct queue too. + */ + rt_thread_mdelay(1); + rt_sem_delete(sem_t); + sem_t = RT_NULL; } static rt_err_t utest_tc_init(void) -- cgit v1.3.1