1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
3 // The test captures what some high-performance networking servers do.
4 // One thread writes to an fd, and another just receives an epoll
5 // notification about the write to synchronize with the first thread
6 // w/o actually reading from the fd.
10 #include <sys/epoll.h>
11 #include <sys/eventfd.h>
14 int efd
= epoll_create(1);
16 exit(printf("epoll_create failed: %d\n", errno
));
17 int fd
= eventfd(0, 0);
19 exit(printf("eventfd failed: %d\n", errno
));
20 epoll_event event
= {.events
= EPOLLIN
| EPOLLET
};
21 if (epoll_ctl(efd
, EPOLL_CTL_ADD
, fd
, &event
))
22 exit(printf("epoll_ctl failed: %d\n", errno
));
26 +[](void *arg
) -> void * {
28 if (write((long)arg
, &to_add
, sizeof(to_add
)) != sizeof(to_add
))
29 exit(printf("write failed: %d\n", errno
));
33 struct epoll_event events
[1] = {};
34 if (epoll_wait(efd
, events
, 1, -1) != 1)
35 exit(printf("epoll_wait failed: %d\n", errno
));
37 pthread_join(th
, nullptr);
39 fprintf(stderr
, "DONE\n");