1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
4 #include <netinet/in.h>
8 #include <sys/socket.h>
12 struct sockaddr_in addr4
;
13 struct sockaddr_in6 addr6
;
14 struct sockaddr
*addr
;
18 void *ClientThread(void *x
) {
20 int c
= socket(addr
->sa_family
, SOCK_STREAM
, IPPROTO_TCP
);
21 if (connect(c
, addr
, addrlen
)) {
25 if (send(c
, "a", 1, 0) != 1) {
34 addr4
.sin_family
= AF_INET
;
35 addr4
.sin_addr
.s_addr
= htonl(INADDR_LOOPBACK
);
36 addr4
.sin_port
= INADDR_ANY
;
37 addr
= (struct sockaddr
*)&addr4
;
38 addrlen
= sizeof(addr4
);
40 int s
= socket(addr
->sa_family
, SOCK_STREAM
, IPPROTO_TCP
);
42 // Try to fall-back to IPv6
43 addr6
.sin6_family
= AF_INET6
;
44 addr6
.sin6_addr
= in6addr_loopback
;
45 addr6
.sin6_port
= INADDR_ANY
;
46 addr
= (struct sockaddr
*)&addr6
;
47 addrlen
= sizeof(addr6
);
48 s
= socket(addr
->sa_family
, SOCK_STREAM
, IPPROTO_TCP
);
52 bind(s
, addr
, addrlen
);
53 getsockname(s
, addr
, &addrlen
);
56 pthread_create(&t
, 0, ClientThread
, 0);
57 int c
= accept(s
, 0, 0);
59 while (read(c
, &buf
, 1) != 1) {
65 fprintf(stderr
, "OK\n");
68 // CHECK-NOT: WARNING: ThreadSanitizer: data race