]> git.saurik.com Git - apple/libdispatch.git/blob - testing/dispatch_overcommit.c
libdispatch-84.5.3.tar.gz
[apple/libdispatch.git] / testing / dispatch_overcommit.c
1 #include <dispatch/dispatch.h>
2 #include <stdio.h>
3 #include <unistd.h>
4 #include <stdlib.h>
5 #include <assert.h>
6 #include <libkern/OSAtomic.h>
7
8 #include "dispatch_test.h"
9
10 int32_t count = 0;
11 const int32_t final = 32;
12
13 int
14 main(void)
15 {
16 test_start("Dispatch Overcommit");
17
18 dispatch_queue_attr_t attr = dispatch_queue_attr_create();
19 test_ptr_notnull("dispatch_queue_attr_create", attr);
20 dispatch_queue_attr_set_flags(attr, DISPATCH_QUEUE_OVERCOMMIT);
21
22 int i;
23 for (i = 0; i < final; ++i) {
24 char* name;
25 asprintf(&name, "test.overcommit.%d", i);
26
27 dispatch_queue_t queue = dispatch_queue_create(name, attr);
28 test_ptr_notnull("dispatch_queue_create", queue);
29 free(name);
30
31 dispatch_async(queue, ^{
32 OSAtomicIncrement32(&count);
33 if (count == final) {
34 test_long("count", count, final);
35 test_stop();
36 } else {
37 while (1); // spin
38 }
39 });
40 }
41
42 dispatch_main();
43
44 return 0;
45 }