Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / lib / tsan / tests / rtl / tsan_thread.cpp
blobfcbeaeaf71cf48200fc86771bed63341cdc11698
1 //===-- tsan_thread.cpp ---------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file is a part of ThreadSanitizer (TSan), a race detector.
11 //===----------------------------------------------------------------------===//
12 #include "tsan_test_util.h"
13 #include "gtest/gtest.h"
15 TEST_F(ThreadSanitizer, ThreadSync) {
16 MainThread t0;
17 MemLoc l;
18 t0.Write1(l);
20 ScopedThread t1;
21 t1.Write1(l);
23 t0.Write1(l);
26 TEST_F(ThreadSanitizer, ThreadDetach1) {
27 ScopedThread t1(true);
28 MemLoc l;
29 t1.Write1(l);
32 TEST_F(ThreadSanitizer, ThreadDetach2) {
33 ScopedThread t1;
34 MemLoc l;
35 t1.Write1(l);
36 t1.Detach();
39 static void *thread_alot_func(void *arg) {
40 (void)arg;
41 int usleep(unsigned);
42 usleep(50);
43 return 0;
46 TEST(DISABLED_SLOW_ThreadSanitizer, ThreadALot) {
47 const int kThreads = 70000;
48 const int kAlive = 1000;
49 pthread_t threads[kAlive] = {};
50 for (int i = 0; i < kThreads; i++) {
51 if (threads[i % kAlive])
52 pthread_join(threads[i % kAlive], 0);
53 pthread_create(&threads[i % kAlive], 0, thread_alot_func, 0);
55 for (int i = 0; i < kAlive; i++) {
56 pthread_join(threads[i], 0);