1//===-- tsan_thread.cc ----------------------------------------------------===// 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// 10// This file is a part of ThreadSanitizer (TSan), a race detector. 11// 12//===----------------------------------------------------------------------===// 13#include "tsan_test_util.h" 14#include "gtest/gtest.h" 15 16TEST(ThreadSanitizer, ThreadSync) { 17 MainThread t0; 18 MemLoc l; 19 t0.Write1(l); 20 { 21 ScopedThread t1; 22 t1.Write1(l); 23 } 24 t0.Write1(l); 25} 26 27TEST(ThreadSanitizer, ThreadDetach1) { 28 ScopedThread t1(true); 29 MemLoc l; 30 t1.Write1(l); 31} 32 33TEST(ThreadSanitizer, ThreadDetach2) { 34 ScopedThread t1; 35 MemLoc l; 36 t1.Write1(l); 37 t1.Detach(); 38} 39 40static void *thread_alot_func(void *arg) { 41 (void)arg; 42 int usleep(unsigned); 43 usleep(50); 44 return 0; 45} 46 47TEST(DISABLED_SLOW_ThreadSanitizer, ThreadALot) { 48 const int kThreads = 70000; 49 const int kAlive = 1000; 50 pthread_t threads[kAlive] = {}; 51 for (int i = 0; i < kThreads; i++) { 52 if (threads[i % kAlive]) 53 pthread_join(threads[i % kAlive], 0); 54 pthread_create(&threads[i % kAlive], 0, thread_alot_func, 0); 55 } 56 for (int i = 0; i < kAlive; i++) { 57 pthread_join(threads[i], 0); 58 } 59} 60