1/* 2 * Copyright (c) 2010 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LLVM_LICENSE_HEADER@ 5 */ 6 7// TEST_CONFIG 8// rdar://problem/6371811 9 10#include <CoreFoundation/CoreFoundation.h> 11#include <dispatch/dispatch.h> 12#include <unistd.h> 13#include <Block.h> 14#include "test.h" 15 16void EnqueueStuff(dispatch_queue_t q) 17{ 18 __block CFIndex counter; 19 20 // above call has a side effect: it works around: 21 // <rdar://problem/6225809> __block variables not implicitly imported into intermediate scopes 22 dispatch_async(q, ^{ 23 counter = 0; 24 }); 25 26 27 dispatch_async(q, ^{ 28 //printf("outer block.\n"); 29 counter++; 30 dispatch_async(q, ^{ 31 //printf("inner block.\n"); 32 counter--; 33 if(counter == 0) { 34 succeed(__FILE__); 35 } 36 }); 37 if(counter == 0) { 38 fail("already done? inconceivable!"); 39 } 40 }); 41} 42 43int main () { 44 dispatch_queue_t q = dispatch_queue_create("queue", NULL); 45 46 EnqueueStuff(q); 47 48 dispatch_main(); 49 fail("unreachable"); 50} 51