]> git.saurik.com Git - apple/libdispatch.git/blob - testing/conc.c
libdispatch-84.5.5.tar.gz
[apple/libdispatch.git] / testing / conc.c
1 #include <stdint.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <stdbool.h>
5 #include <unistd.h>
6 #include <errno.h>
7 #include <string.h>
8 #include <assert.h>
9 #include <dispatch.h>
10 #include <dispatch_private.h>
11 #include <pthread.h>
12
13 int
14 main(void)
15 {
16 dispatch_block_t wb = ^(dispatch_item_t di) { printf("\t\t%p\tstart\n", pthread_self()); sleep(3); };
17 dispatch_block_t cb = ^(dispatch_item_t di) { printf("\t\t%p\tdone\n", pthread_self()); };
18 dispatch_queue_t dq;
19 bool r;
20 int i;
21
22 dq = dispatch_queue_new("conc", DISPATCH_QUEUE_CONCURRENT, NULL, NULL, NULL);
23 assert(dq);
24
25 for (i = 0; i < 10; i++) {
26 r = dispatch_call(dq, wb, cb, NULL, NULL);
27 assert(r);
28 }
29
30 dispatch_main();
31
32 return 0;
33 }