1// Check that init-order checking is properly disabled if pthread_create is
2// called.
3
4// RUN: %clangxx_asan %s %p/Helpers/init-order-pthread-create-extra.cc -pthread -o %t
5// RUN: env ASAN_OPTIONS=strict_init_order=true %run %t
6
7#include <stdio.h>
8#include <pthread.h>
9#include <unistd.h>
10
11void *bar(void *input, bool sleep_before_init) {
12  if (sleep_before_init)
13    usleep(500000);
14  return input;
15}
16
17void *glob = bar((void*)0x1234, false);
18extern void *glob2;
19
20void *poll(void *arg) {
21  void **glob = (void**)arg;
22  while (true) {
23    usleep(100000);
24    printf("glob is now: %p\n", *glob);
25  }
26}
27
28struct GlobalPollerStarter {
29  GlobalPollerStarter() {
30    pthread_t p;
31    pthread_attr_t attr;
32    pthread_attr_init(&attr);
33    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
34    pthread_create(&p, 0, poll, &glob);
35    pthread_attr_destroy(&attr);
36    printf("glob poller is started");
37  }
38} global_poller;
39
40int main() {
41  printf("%p %p\n", glob, glob2);
42  return 0;
43}
44