• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: %clang_tsan %s -o %t -framework Foundation
2// RUN: %run %t 2>&1 | FileCheck %s
3
4// UNSUPPORTED: ios
5
6#import <Foundation/Foundation.h>
7#import <xpc/xpc.h>
8
9long global;
10
11int main(int argc, const char *argv[]) {
12  fprintf(stderr, "Hello world.\n");
13
14  dispatch_queue_t server_q = dispatch_queue_create("server.queue", DISPATCH_QUEUE_CONCURRENT);
15  xpc_connection_t server_conn = xpc_connection_create(NULL, server_q);
16
17  xpc_connection_set_event_handler(server_conn, ^(xpc_object_t client) {
18    if (client == XPC_ERROR_CONNECTION_INTERRUPTED || client == XPC_ERROR_CONNECTION_INVALID) {
19      global = 43;
20
21      dispatch_async(dispatch_get_main_queue(), ^{
22        CFRunLoopStop(CFRunLoopGetCurrent());
23      });
24    }
25  });
26  xpc_connection_resume(server_conn);
27
28  global = 42;
29
30  xpc_connection_cancel(server_conn);
31
32  CFRunLoopRun();
33
34  fprintf(stderr, "Done.\n");
35}
36
37// CHECK: Hello world.
38// CHECK-NOT: WARNING: ThreadSanitizer
39// CHECK: Done.
40