@@ -37,15 +37,7 @@ static volatile int32_t busy_threads_started, busy_threads_finished;
37
37
/*
38
38
* Keep a thread busy, spinning on the CPU.
39
39
*/
40
- #if TARGET_OS_EMBEDDED
41
- // iPhone 4
42
- #define ITERS_PER_SECOND 50000000UL
43
- #elif __s390x__
44
- #define ITERS_PER_SECOND 15000000000UL
45
- #else
46
- // On a 2.7 4-core i5 iMac12,2, one thread of this loop runs at ROUGHLY:
47
- #define ITERS_PER_SECOND 1000000000UL
48
- #endif
40
+ static volatile int all_done = 0 ;
49
41
50
42
/* Fiddling with j in the middle and hitting this global will hopefully keep
51
43
* the optimizer from cutting the whole thing out as dead code.
@@ -54,14 +46,16 @@ static volatile unsigned int busythread_useless;
54
46
void busythread (void * ignored )
55
47
{
56
48
(void )ignored ;
57
- uint64_t i = 0 , j = 0 ;
49
+ /* prevent i and j been optimized out */
50
+ volatile uint64_t i = 0 , j = 0 ;
58
51
59
52
OSAtomicIncrement32 (& busy_threads_started );
60
53
61
- for ( i = 0 ; i < 2 * ITERS_PER_SECOND ; i ++ )
54
+ while (! all_done )
62
55
{
63
56
if (i == 500000 ) { j -= busythread_useless ; }
64
57
j += i ;
58
+ i += 1 ;
65
59
}
66
60
67
61
OSAtomicIncrement32 (& busy_threads_finished );
@@ -109,6 +103,9 @@ void test_apply_contended(dispatch_queue_t dq)
109
103
test_long ("contended: count" , count , final );
110
104
test_long ("contended: threads finished before apply" , after , 0 );
111
105
106
+ /* Release busy threads by setting all_done to 1 */
107
+ all_done = 1 ;
108
+
112
109
dispatch_group_wait (grp , DISPATCH_TIME_FOREVER );
113
110
dispatch_release (grp );
114
111
0 commit comments