[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / compiler-rt / test / tsan / libdispatch / target-queue-norace.c
blob893e0c4f4dcd72ba98f8a9b98893c1cf8ca58264
1 // RUN: %clang_tsan %s -o %t
2 // RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
4 #include "dispatch/dispatch.h"
6 #include <stdio.h>
8 long global;
10 int main(int argc, const char *argv[]) {
11 dispatch_semaphore_t done = dispatch_semaphore_create(0);
12 dispatch_queue_t target_queue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL);
13 dispatch_queue_t q1 = dispatch_queue_create(NULL, DISPATCH_QUEUE_CONCURRENT);
14 dispatch_queue_t q2 = dispatch_queue_create(NULL, DISPATCH_QUEUE_CONCURRENT);
15 dispatch_set_target_queue(q1, target_queue);
16 dispatch_set_target_queue(q2, target_queue);
18 for (int i = 0; i < 100000; i++) {
19 dispatch_async(q1, ^{
20 global++;
22 if (global == 200000) {
23 dispatch_semaphore_signal(done);
25 });
26 dispatch_async(q2, ^{
27 global++;
29 if (global == 200000) {
30 dispatch_semaphore_signal(done);
32 });
35 dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
36 fprintf(stderr, "Done.\n");
37 return 0;
40 // CHECK: Done.