Nick Lewycky | 4d0a9ff | 2011-11-14 20:50:16 +0000 | [diff] [blame] | 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" |
Nick Lewycky | f7228f7 | 2011-11-14 22:10:23 +0000 | [diff] [blame] | 10 | #include "llvm/Config/config.h" |
Chandler Carruth | 5a88dda | 2012-12-04 10:23:08 +0000 | [diff] [blame^] | 11 | #include "llvm/Support/Threading.h" |
Nick Lewycky | f7228f7 | 2011-11-14 22:10:23 +0000 | [diff] [blame] | 12 | #ifdef HAVE_PTHREAD_H |
Nick Lewycky | 4d0a9ff | 2011-11-14 20:50:16 +0000 | [diff] [blame] | 13 | #include <pthread.h> |
Nick Lewycky | f7228f7 | 2011-11-14 22:10:23 +0000 | [diff] [blame] | 14 | #endif |
Nick Lewycky | 4d0a9ff | 2011-11-14 20:50:16 +0000 | [diff] [blame] | 15 | |
| 16 | #include "gtest/gtest.h" |
| 17 | |
| 18 | using namespace llvm; |
| 19 | |
| 20 | namespace { |
| 21 | |
Nick Lewycky | f7228f7 | 2011-11-14 22:10:23 +0000 | [diff] [blame] | 22 | #ifdef HAVE_PTHREAD_H |
Nick Lewycky | 4d0a9ff | 2011-11-14 20:50:16 +0000 | [diff] [blame] | 23 | namespace test1 { |
| 24 | llvm::ManagedStatic<int> ms; |
| 25 | void *helper(void*) { |
| 26 | *ms; |
| 27 | return NULL; |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | TEST(Initialize, MultipleThreads) { |
| 32 | // Run this test under tsan: http://code.google.com/p/data-race-test/ |
| 33 | |
| 34 | llvm_start_multithreaded(); |
| 35 | pthread_t t1, t2; |
| 36 | pthread_create(&t1, NULL, test1::helper, NULL); |
| 37 | pthread_create(&t2, NULL, test1::helper, NULL); |
| 38 | pthread_join(t1, NULL); |
| 39 | pthread_join(t2, NULL); |
| 40 | llvm_stop_multithreaded(); |
| 41 | } |
Nick Lewycky | f7228f7 | 2011-11-14 22:10:23 +0000 | [diff] [blame] | 42 | #endif |
Nick Lewycky | 4d0a9ff | 2011-11-14 20:50:16 +0000 | [diff] [blame] | 43 | |
| 44 | } // anonymous namespace |