third_party/libunwindstack/tests/UnwindTest.cpp
TEST_F(UnwindTest, multiple_threads_unwind_same_map) {
  static constexpr size_t kNumConcurrentThreads = 100;

  LocalMaps maps;
  ASSERT_TRUE(maps.Parse());
  auto process_memory(Memory::CreateProcessMemory(getpid()));

  std::vector<std::thread*> threads;

  std::atomic_bool wait;
  wait = true;
  size_t frames[kNumConcurrentThreads];
  for (size_t i = 0; i < kNumConcurrentThreads; i++) {
    std::thread* thread = new std::thread([i, &frames, &maps, &process_memory, &wait]() {
      while (wait)
        ;
      std::unique_ptr<Regs> regs(Regs::CreateFromLocal());
      RegsGetLocal(regs.get());

      Unwinder unwinder(512, &maps, regs.get(), process_memory);
      unwinder.Unwind();
      frames[i] = unwinder.NumFrames();
      ASSERT_LE(3U, frames[i]) << "Failed for thread " << i;
    });
    threads.push_back(thread);
  }
  wait = false;
  for (auto thread : threads) {
    thread->join();
    delete thread;
  }
}
// Verify that using the same map while unwinding multiple threads at the
// same time doesn't cause problems.
Verify that using the same map while unwinding multiple threads at the
same time doesn't cause problems.
Verify that using the same map while unwinding multiple threads at the same time doesn ' t cause problems .
TEST_F(UnwindTest, multiple_threads_unwind_same_map) {
  static constexpr size_t kNumConcurrentThreads = 100;
  LocalMaps maps;
  ASSERT_TRUE(maps.Parse());
  auto process_memory(Memory::CreateProcessMemory(getpid()));
  std::vector<std::thread*> threads;
  std::atomic_bool wait;
  wait = true;
  size_t frames[kNumConcurrentThreads];
  for (size_t i = 0; i < kNumConcurrentThreads; i++) {
    std::thread* thread = new std::thread([i, &frames, &maps, &process_memory, &wait]() {
      while (wait)
        ;
      std::unique_ptr<Regs> regs(Regs::CreateFromLocal());
      RegsGetLocal(regs.get());
      Unwinder unwinder(512, &maps, regs.get(), process_memory);
      unwinder.Unwind();
      frames[i] = unwinder.NumFrames();
      ASSERT_LE(3U, frames[i]) << "Failed for thread " << i;
    });
    threads.push_back(thread);
  }
  wait = false;
  for (auto thread : threads) {
    thread->join();
    delete thread;
  }
}
TEST_F ( UnwindTest , multiple_threads_unwind_same_map ) { static constexpr size_t kNumConcurrentThreads = 100 ; LocalMaps maps ; ASSERT_TRUE ( maps . Parse ( ) ) ; auto process_memory ( Memory :: CreateProcessMemory ( getpid ( ) ) ) ; std :: vector < std :: thread * > threads ; std :: atomic_bool wait ; wait = true ; size_t frames [ kNumConcurrentThreads ] ; for ( size_t i = 0 ; i < kNumConcurrentThreads ; i ++ ) { std :: thread * thread = new std :: thread ( [ i , & frames , & maps , & process_memory , & wait ] ( ) { while ( wait ) ; std :: unique_ptr < Regs > regs ( Regs :: CreateFromLocal ( ) ) ; RegsGetLocal ( regs . get ( ) ) ; Unwinder unwinder ( 512 , & maps , regs . get ( ) , process_memory ) ; unwinder . Unwind ( ) ; frames [ i ] = unwinder . NumFrames ( ) ; ASSERT_LE ( 3U , frames [ i ] ) << " " << i ; } ) ; threads . push_back ( thread ) ; } wait = false ; for ( auto thread : threads ) { thread -> join ( ) ; delete thread ; } }
Verify that using the same map while unwinding multiple threads at the
same time doesn't cause problems.
Verify that using the same map while unwinding multiple threads at the same time doesn ' t cause problems .