Skip to content

Commit 3f01125

Browse files
M-Moawadkartben
authored andcommitted
tests: kernel: fix thread_runtime_stats compiler optimization issue
Compilers may optimize away empty while(1){} loops in helper threads, causing the idle thread to run instead and breaking runtime statistics measurement. Use volatile condition variable to prevent optimization. Signed-off-by: Mohamed Moawad <[email protected]>
1 parent 240d99f commit 3f01125

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

tests/kernel/usage/thread_runtime_stats/src/test_thread_runtime_stats.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ static struct k_thread *main_thread;
3333
*/
3434
void helper1(void *p1, void *p2, void *p3)
3535
{
36-
while (1) {
36+
/* Using volatile condition to prevent compilers from optimizing while(true) */
37+
volatile bool condition = true;
38+
39+
while (condition) {
3740
}
3841
}
3942

0 commit comments

Comments
 (0)