3 #include <dispatch/dispatch.h>
4 #include <dispatch/private.h>
6 #include <sys/sysctl.h>
8 #include "darwintest_defaults.h"
9 #include <darwintest_utils.h>
11 static uint64_t end_spin
;
16 static uint32_t activecpu
;
19 size_t s
= sizeof(activecpu
);
20 sysctlbyname("hw.activecpu", &n
, &s
, NULL
, 0);
27 spin_and_pause(void *ctx
)
31 printf("Thread %ld starts\n", i
);
33 while (clock_gettime_nsec_np(CLOCK_MONOTONIC
) < end_spin
) {
34 #if defined(__x86_64__) || defined(__i386__)
36 #elif defined(__arm__) || defined(__arm64__)
40 printf("Thread %ld blocks\n", i
);
49 printf("Thread %ld starts\n", i
);
51 while (clock_gettime_nsec_np(CLOCK_MONOTONIC
)) {
52 #if defined(__x86_64__) || defined(__i386__)
54 #elif defined(__arm__) || defined(__arm64__)
60 T_DECL(thread_request_32848402
, "repro for rdar://32848402")
62 dispatch_queue_attr_t bg_attr
, in_attr
;
64 bg_attr
= dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_CONCURRENT
,
65 QOS_CLASS_BACKGROUND
, 0);
66 in_attr
= dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_CONCURRENT
,
67 QOS_CLASS_USER_INITIATED
, 0);
69 dispatch_queue_t a
= dispatch_queue_create_with_target("in", in_attr
, NULL
);
70 dispatch_queue_t b
= dispatch_queue_create_with_target("bg", bg_attr
, NULL
);
72 end_spin
= clock_gettime_nsec_np(CLOCK_MONOTONIC
) + 2 * NSEC_PER_SEC
;
74 dispatch_async_f(a
, (void *)0, spin_and_pause
);
75 for (long i
= 1; i
< get_ncpu(); i
++) {
76 dispatch_async_f(b
, (void *)i
, spin
);
80 T_PASS("The NCPU+1-nth block got scheduled");
85 T_FAIL("The NCPU+1-nth block didn't get scheduled");