summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYunlk <[email protected]>2026-11-13 09:37:00 +0800
committerGitHub <[email protected]>2026-11-13 09:37:00 +0800
commit21834bf76ef335ef622dec38e4a8b3c717a5e146 (patch)
treec9191c74b8d173c6f273d94f10897063036ad777
parent4aaa84ba177657a5eaffa074164bd45e2cc79d36 (diff)
[utest][atomic] release worker threads and semaphore between runs
在每轮原子操作测试结束后让出执行机会并删除信号量,避免重复运行时累积测试资源。
-rw-r--r--src/utest/atomic_tc.c20
1 files changed, 20 insertions, 0 deletions
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)