f1f03208c1f0a6f2bbe40362d89b7577bd1cad97
[oota-llvm.git] / unittests / Support / ManagedStatic.cpp
1 //===- llvm/unittest/Support/ManagedStatic.cpp - ManagedStatic tests ------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 #include "llvm/Support/ManagedStatic.h"
10 #include "llvm/Support/Threading.h"
11 #include <pthread.h>
12
13 #include "gtest/gtest.h"
14
15 using namespace llvm;
16
17 namespace {
18
19 namespace test1 {
20   llvm::ManagedStatic<int> ms;
21   void *helper(void*) {
22     *ms;
23     return NULL;
24   }
25 }
26
27 TEST(Initialize, MultipleThreads) {
28   // Run this test under tsan: http://code.google.com/p/data-race-test/
29
30   llvm_start_multithreaded();
31   pthread_t t1, t2;
32   pthread_create(&t1, NULL, test1::helper, NULL);
33   pthread_create(&t2, NULL, test1::helper, NULL);
34   pthread_join(t1, NULL);
35   pthread_join(t2, NULL);
36   llvm_stop_multithreaded();
37 }
38
39 } // anonymous namespace