[Sanitizer] Add rudimentary support for wide-character strings to scanf/printf interc...
[blocksruntime.git] / test / BlocksRuntime / dispatch_async.c
blobe3e517c54650e31815a5701f5f1b10494ec3a223
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
7 #include <CoreFoundation/CoreFoundation.h>
9 #include <dispatch/dispatch.h>
10 #include <unistd.h>
11 //#import <Foundation/Foundation.h>
12 #include <Block.h>
14 // CONFIG rdar://problem/6371811
16 const char *whoami = "nobody";
18 void EnqueueStuff(dispatch_queue_t q)
20 __block CFIndex counter;
22 // above call has a side effect: it works around:
23 // <rdar://problem/6225809> __block variables not implicitly imported into intermediate scopes
24 dispatch_async(q, ^{
25 counter = 0;
26 });
29 dispatch_async(q, ^{
30 //printf("outer block.\n");
31 counter++;
32 dispatch_async(q, ^{
33 //printf("inner block.\n");
34 counter--;
35 if(counter == 0) {
36 printf("%s: success\n", whoami);
37 exit(0);
39 });
40 if(counter == 0) {
41 printf("already done? inconceivable!\n");
42 exit(1);
44 });
47 int main (int argc, const char * argv[]) {
48 dispatch_queue_t q = dispatch_queue_create("queue", NULL);
50 whoami = argv[0];
52 EnqueueStuff(q);
54 dispatch_main();
55 printf("shouldn't get here\n");
56 return 1;