Index: vm/tests/unit/thread/test_native_basic.c =================================================================== --- vm/tests/unit/thread/test_native_basic.c (revision 541439) +++ vm/tests/unit/thread/test_native_basic.c (working copy) @@ -18,6 +18,7 @@ #include #include "thread_private.h" #include +#include #include "testframe.h" #include "jthread.h" #include @@ -61,6 +62,37 @@ return TEST_PASSED; } +// Waits until count of running threads in specified group reaches 'count' or less +static void wait_for_all_treads_are_terminated(hythread_group_t group, int count) +{ + int max_tries = 1000; // Maximum count of iterations + + while (max_tries--) + { + int n = 0; + hythread_t thread; + + hythread_iterator_t iterator = hythread_iterator_create(group); + + while(hythread_iterator_has_next(iterator)) + { + thread = hythread_iterator_next(&iterator); + + if (!hythread_is_terminated(thread)) + ++n; + } + + hythread_iterator_release(&iterator); + + if (n <= count) + break; + + apr_sleep(1000); // 1ms + } + + apr_sleep(100000);// 0.1s to let system threads finish their work +} + hylatch_t start; hylatch_t end; @@ -96,9 +128,11 @@ } tf_assert(i == n); - + hythread_iterator_release(&iterator); - + + wait_for_all_treads_are_terminated(group, i - n); + return 0; } @@ -131,9 +165,11 @@ } tf_assert(i >= n); - + hythread_iterator_release(&iterator); - + + wait_for_all_treads_are_terminated(NULL, i - n); + return 0; }