1// RUN: %clangxx_tsan -O1 %s -o %t && %run %t | FileCheck %s
2// Regtest for https://code.google.com/p/thread-sanitizer/issues/detail?id=40
3// This is a correct program and tsan should not report a race.
4#include <pthread.h>
5#include <unistd.h>
6#include <stdio.h>
7int g;
8__attribute__((noinline))
9int foo(int cond) {
10  if (cond)
11    return g;
12  return 0;
13}
14void *Thread1(void *p) {
15  long res = foo((long)p);
16  sleep(1);
17  return (void*) res;
18}
19
20int main() {
21  pthread_t t;
22  pthread_create(&t, 0, Thread1, 0);
23  g = 1;
24  pthread_join(t, 0);
25  printf("PASS\n");
26  // CHECK: PASS
27}
28