[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / compiler-rt / test / tsan / libdispatch / fd.c
blob107f6252d7b077ff704f59514cda2be0bb0bdcde
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 my_global = 0;
10 int main(int argc, const char *argv[]) {
11 fprintf(stderr, "Hello world.\n");
13 dispatch_queue_t queue = dispatch_queue_create("my.queue", DISPATCH_QUEUE_SERIAL);
14 dispatch_semaphore_t sem = dispatch_semaphore_create(0);
16 const char *path = tempnam(NULL, "libdispatch-fd-");
18 dispatch_io_t channel = dispatch_io_create_with_path(DISPATCH_IO_STREAM, path, O_CREAT | O_WRONLY,
19 0666, queue, ^(int error) { });
20 dispatch_io_set_high_water(channel, 1);
22 char buf[1000];
23 dispatch_data_t data = dispatch_data_create(buf, sizeof(buf), NULL, DISPATCH_DATA_DESTRUCTOR_DEFAULT);
25 my_global++;
26 dispatch_io_write(channel, 0, data, queue, ^(bool done, dispatch_data_t remainingData, int error) {
27 my_global++;
28 dispatch_async(queue, ^{
29 my_global++;
30 if (done) {
31 dispatch_semaphore_signal(sem);
33 });
34 });
36 dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
37 my_global++;
38 dispatch_io_close(channel, 0);
39 channel = dispatch_io_create_with_path(DISPATCH_IO_STREAM, path, O_RDONLY,
40 0, queue, ^(int error) { });
41 dispatch_io_set_high_water(channel, 1);
43 my_global++;
44 dispatch_io_read(channel, 0, SIZE_MAX, queue, ^(bool done, dispatch_data_t remainingData, int error) {
45 my_global++;
46 dispatch_async(queue, ^{
47 my_global++;
48 if (done) {
49 dispatch_semaphore_signal(sem);
51 });
52 });
54 dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
55 my_global++;
56 fprintf(stderr, "Done.\n");
57 return 0;
60 // CHECK: Hello world.
61 // CHECK: Done.