• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: %clangxx_tsan %s -o %t -framework Foundation
2// RUN: %env_tsan_opts=ignore_interceptors_accesses=1 %run %t 2>&1 | FileCheck %s
3
4#import <Foundation/Foundation.h>
5
6#import <memory>
7
8#import "../test.h"
9
10long my_global;
11
12struct MyStruct {
13  void setGlobal() {
14    my_global = 42;
15  }
16  ~MyStruct() {
17    my_global = 43;
18  }
19};
20
21int main(int argc, const char *argv[]) {
22  fprintf(stderr, "Hello world.\n");
23  print_address("addr=", 1, &my_global);
24  barrier_init(&barrier, 2);
25
26  std::shared_ptr<MyStruct> shared(new MyStruct());
27
28  dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
29
30  std::weak_ptr<MyStruct> weak(shared);
31
32  dispatch_async(q, ^{
33    {
34      std::shared_ptr<MyStruct> strong = weak.lock();
35      if (!strong) exit(1);
36
37      strong->setGlobal();
38    }
39    barrier_wait(&barrier);
40  });
41
42  barrier_wait(&barrier);
43  shared.reset();
44
45  fprintf(stderr, "Done.\n");
46}
47
48// CHECK: Hello world.
49// CHECK: Done.
50// CHECK-NOT: WARNING: ThreadSanitizer
51