return 1;
}
}
- fprintf(stderr, "\tsuccessfully signaled by %d threads.\n", threads);
+ fprintf(stderr, "\tsuccessfully signaled by %d threads.\n\n", threads);
return 0;
}
dispatch_semaphore_signal(sema);
}
-void (^cb)(void) = NULL;
+void (^cb)(pthread_priority_t p) = NULL;
static void workqueue_func_kevent(void **buf, int *count){
pthread_priority_t p = (pthread_priority_t)pthread_getspecific(4);
- fprintf(stderr, "\tthread with qos %s spawned.\n", describe_pri(p));
+ fprintf(stderr, "\tthread with qos %s spawned. (buf: %p, count: %d)\n", describe_pri(p), buf ? *buf : NULL, count ? *count : 0);
if (cb){
- cb();
+ cb(p);
}
dispatch_semaphore_signal(sema);
if ((ret = do_req()) < 0) return ret;
if ((ret = do_wait(1)) < 0) return ret;
- // whole bunch of constrained threads
+ // whole bunch of constrained threads (must be last)
+
+ dispatch_semaphore_t mgr_sema = dispatch_semaphore_create(0);
+ assert(mgr_sema != NULL);
requests[0].priority = _pthread_qos_class_encode(QOS_CLASS_USER_INTERACTIVE, 0, 0);
requests[0].count = 1;
- cb = ^{
+ cb = ^(pthread_priority_t p){
+ if (p & _PTHREAD_PRIORITY_EVENT_MANAGER_FLAG){
+ dispatch_semaphore_signal(mgr_sema);
+ }
+
// burn some CPU
for (int i = 0; i < 1000000; i++){
char c[32];
};
for (int i = 0; i < 8; i++)
if ((ret = do_req()) < 0) return ret;
- if ((ret = do_wait(8)) < 0) return ret;
+ ret = dispatch_semaphore_wait(mgr_sema, timeout);
+ if (ret) {
+ fprintf(stderr, "timeout waiting for a manager thread");
+ return 1;
+ }
+ fprintf(stderr, "\tsucessfully signaled by a manager thread.\n");
return 0;
}