3 #include <sys/socket.h>
11 struct data threaddat
[] = {
12 { "www.freebsd.org", 0 },
13 { "www.google.com", 0 },
14 { "www.freshports.org", 0 },
15 { "www.github.com", 0 },
16 { "www.kernel.org", 0 },
17 { "petunia.bogus.address", 0 }
20 static const size_t threaddat_size
= sizeof(threaddat
)/sizeof(threaddat
[0]);
22 pthread_t threads
[sizeof(threaddat
)/sizeof(threaddat
[0])];
24 void *resolve(void *d
) {
25 struct data
*data
= d
;
26 getaddrinfo(data
->hostname
, 0, 0, &data
->res
);
32 for (i
= 0; i
< threaddat_size
; ++i
) {
33 pthread_create(&threads
[i
], 0, resolve
, &threaddat
[i
]);
35 for (i
= 0; i
< threaddat_size
; ++i
) {
36 pthread_join(threads
[i
], 0);
37 // musl crashes if you pass a NULL pointer to freeaddrinfo
40 freeaddrinfo(threaddat
[i
].res
);