[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / compiler-rt / test / tsan / libdispatch / data.c
blob70c503bda601010de3da8a9c8c775b234914cf40
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>
7 #include <string.h>
9 long global = 42;
11 int main(int argc, const char *argv[]) {
12 fprintf(stderr, "Hello world.\n");
14 dispatch_queue_t q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_SERIAL);
15 dispatch_semaphore_t sem = dispatch_semaphore_create(0);
17 const char *buffer = "buffer";
18 size_t size = strlen(buffer);
20 dispatch_data_t data = dispatch_data_create(buffer, size, q, ^{
21 fprintf(stderr, "Data destructor.\n");
22 global++;
24 dispatch_semaphore_signal(sem);
25 });
26 dispatch_release(data);
28 dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
30 data = dispatch_data_create(buffer, size, q, DISPATCH_DATA_DESTRUCTOR_DEFAULT);
31 dispatch_release(data);
33 fprintf(stderr, "Done.\n");
36 // CHECK: Hello world.
37 // CHECK: Data destructor.
38 // CHECK: Done.