]> git.proxmox.com Git - rustc.git/blob - src/compiler-rt/test/tsan/Darwin/gcd-target-queue-norace.mm
New upstream version 1.19.0+dfsg3
[rustc.git] / src / compiler-rt / test / tsan / Darwin / gcd-target-queue-norace.mm
1 // RUN: %clang_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 long global;
7
8 int main(int argc, const char *argv[]) {
9 dispatch_queue_t target_queue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL);
10 dispatch_queue_t q1 = dispatch_queue_create(NULL, DISPATCH_QUEUE_CONCURRENT);
11 dispatch_queue_t q2 = dispatch_queue_create(NULL, DISPATCH_QUEUE_CONCURRENT);
12 dispatch_set_target_queue(q1, target_queue);
13 dispatch_set_target_queue(q2, target_queue);
14
15 for (int i = 0; i < 100000; i++) {
16 dispatch_async(q1, ^{
17 global++;
18
19 if (global == 200000) {
20 dispatch_sync(dispatch_get_main_queue(), ^{
21 CFRunLoopStop(CFRunLoopGetCurrent());
22 });
23 }
24 });
25 dispatch_async(q2, ^{
26 global++;
27
28 if (global == 200000) {
29 dispatch_sync(dispatch_get_main_queue(), ^{
30 CFRunLoopStop(CFRunLoopGetCurrent());
31 });
32 }
33 });
34 }
35
36 CFRunLoopRun();
37 NSLog(@"Done.");
38 return 0;
39 }
40
41 // CHECK-NOT: WARNING: ThreadSanitizer