lundi 20 février 2023

Core dump while spawning/joining threads inside Google benchmark test

I am getting core dump while trying to spawn and then join the threads inside google benchmark. This is irrespective of the number of threads I try to create.

Code to reproduce the issue:

void BM_ThreadsTest(benchmark::State &state)
{
  std::atomic<size_t> curr_processed {0};
  constexpr size_t max_processed = 100;
  constexpr size_t NUM_CORES = 24; //get programmatically
  std::vector<std::thread> threads;
  while (state.KeepRunning())
  {
    for (int i = 0; i < NUM_CORES; i++){
      threads.push_back(std::thread( [&curr_processed, &max_processed]() {
        while (curr_processed <= max_processed)
        {
          curr_processed++;
        }
      }));
    }
    for (auto &th: threads){
      th.join();
    }
   }
  }
  BENCHMARK(BM_ThreadsTest);
  BENCHMARK_MAIN();

Error:

terminate called after throwing an instance of 'std::system_error'
  what():  Invalid argument
Aborted (core dumped)

Stacktrace:

(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x00007fc21548b859 in __GI_abort () at abort.c:79
#2  0x00007fc215714a31 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#3  0x00007fc2157205dc in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#4  0x00007fc215720647 in std::terminate() () from /lib/x86_64-linux-gnu/libstdc++.so.6
#5  0x00007fc2157208e9 in __cxa_throw () from /lib/x86_64-linux-gnu/libstdc++.so.6
#6  0x00007fc2157177e5 in std::__throw_system_error(int) () from /lib/x86_64-linux-gnu/libstdc++.so.6
#7  0x00007fc21574d930 in std::thread::join() () from /lib/x86_64-linux-gnu/libstdc++.so.6
#8  0x000055e40166b6a2 in (anonymous namespace)::BM_MeasurementsTest(benchmark::State&) ()
#9  0x00007fc2158e972f in benchmark::internal::BenchmarkInstance::Run(unsigned long, int, benchmark::internal::ThreadTimer*, benchmark::internal::ThreadManager*) const () from /lib/x86_64-linux-gnu/libbenchmark.so.1
#10 0x00007fc2158d5f59 in ?? () from /lib/x86_64-linux-gnu/libbenchmark.so.1
#11 0x00007fc2158d681e in benchmark::internal::RunBenchmark(benchmark::internal::BenchmarkInstance const&, std::vector<benchmark::BenchmarkReporter::Run, std::allocator<benchmark::BenchmarkReporter::Run> >*) ()
   from /lib/x86_64-linux-gnu/libbenchmark.so.1
#12 0x00007fc2158ee7cc in benchmark::RunSpecifiedBenchmarks(benchmark::BenchmarkReporter*, benchmark::BenchmarkReporter*) () from /lib/x86_64-linux-gnu/libbenchmark.so.1
#13 0x000055e40166b757 in main ()

Aucun commentaire:

Enregistrer un commentaire