brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · fcbeaea Raw
59 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8//9// This file is a part of ThreadSanitizer (TSan), a race detector.10//11//===----------------------------------------------------------------------===//12#include "tsan_test_util.h"13#include "gtest/gtest.h"14 15TEST_F(ThreadSanitizer, ThreadSync) {16  MainThread t0;17  MemLoc l;18  t0.Write1(l);19  {20    ScopedThread t1;21    t1.Write1(l);22  }23  t0.Write1(l);24}25 26TEST_F(ThreadSanitizer, ThreadDetach1) {27  ScopedThread t1(true);28  MemLoc l;29  t1.Write1(l);30}31 32TEST_F(ThreadSanitizer, ThreadDetach2) {33  ScopedThread t1;34  MemLoc l;35  t1.Write1(l);36  t1.Detach();37}38 39static void *thread_alot_func(void *arg) {40  (void)arg;41  int usleep(unsigned);42  usleep(50);43  return 0;44}45 46TEST(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);54  }55  for (int i = 0; i < kAlive; i++) {56    pthread_join(threads[i], 0);57  }58}59