diff --git a/src/utest/mailbox_tc.c b/src/utest/mailbox_tc.c index b51ee6e515e..6d7ce132878 100644 --- a/src/utest/mailbox_tc.c +++ b/src/utest/mailbox_tc.c @@ -389,6 +389,17 @@ static void test_dynamic_mailbox_send_recv(void) static rt_err_t utest_tc_init(void) { + /* This testcase may be run more than once in a single boot. The finish + * flags are set by the worker threads and read by the test body, so they + * must be cleared before every run. Otherwise the second run would skip + * the wait loop, detach/delete the mailbox while the worker threads are + * still blocked in rt_mb_recv(), and those threads would then use an + * already detached mailbox. */ + static_mb_recv_thread_finish = 0; + static_mb_send_thread_finish = 0; + dynamic_mb_recv_thread_finish = 0; + dynamic_mb_send_thread_finish = 0; + return RT_EOK; }