blob: 12362fc440dcc1b52b97122b3170d4ef3db1798f [file] [log] [blame]
Stephen Hines2d1fdb22014-05-28 23:58:16 -07001// Check that init-order checking is properly disabled if pthread_create is
2// called.
3
Stephen Hines6a211c52014-07-21 00:49:56 -07004// RUN: %clangxx_asan %s %p/Helpers/init-order-pthread-create-extra.cc -pthread -o %t
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -07005// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_init_order=true %run %t
Stephen Hines2d1fdb22014-05-28 23:58:16 -07006
7#include <stdio.h>
8#include <pthread.h>
Stephen Hines86277eb2015-03-23 12:06:32 -07009#include <unistd.h>
Stephen Hines2d1fdb22014-05-28 23:58:16 -070010
Stephen Hines86277eb2015-03-23 12:06:32 -070011void *bar(void *input, bool sleep_before_init) {
12 if (sleep_before_init)
13 usleep(500000);
Stephen Hines2d1fdb22014-05-28 23:58:16 -070014 return input;
15}
16
Stephen Hines86277eb2015-03-23 12:06:32 -070017void *glob = bar((void*)0x1234, false);
Stephen Hines2d1fdb22014-05-28 23:58:16 -070018extern void *glob2;
19
Stephen Hines86277eb2015-03-23 12:06:32 -070020void *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
Stephen Hines2d1fdb22014-05-28 23:58:16 -070040int main() {
41 printf("%p %p\n", glob, glob2);
42 return 0;
43}