llvm-project
56 строк · 1.3 Кб
1//
2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3// See https://llvm.org/LICENSE.txt for license information.
4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5
6#include <CoreFoundation/CoreFoundation.h>7
8#include <dispatch/dispatch.h>9#include <unistd.h>10//#import <Foundation/Foundation.h>
11#include <Block.h>12
13// CONFIG rdar://problem/6371811
14
15const char *whoami = "nobody";16
17void EnqueueStuff(dispatch_queue_t q)18{
19__block CFIndex counter;20
21// above call has a side effect: it works around:22// <rdar://problem/6225809> __block variables not implicitly imported into intermediate scopes23dispatch_async(q, ^{24counter = 0;25});26
27
28dispatch_async(q, ^{29//printf("outer block.\n");30counter++;31dispatch_async(q, ^{32//printf("inner block.\n");33counter--;34if(counter == 0) {35printf("%s: success\n", whoami);36exit(0);37}38});39if(counter == 0) {40printf("already done? inconceivable!\n");41exit(1);42}43});44}
45
46int main (int argc, const char * argv[]) {47dispatch_queue_t q = dispatch_queue_create("queue", NULL);48
49whoami = argv[0];50
51EnqueueStuff(q);52
53dispatch_main();54printf("shouldn't get here\n");55return 1;56}
57