[PATCH] D142318: [Support] Add PerThreadBumpPtrAllocator class.

Duncan P. N. Exon Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 14 11:09:04 PDT 2023


dexonsmith added a comment.

In D142318#4269070 <https://reviews.llvm.org/D142318#4269070>, @dexonsmith wrote:

> Seems like threads are assigned IDs from 1 in the ThreadPoolExecutor constructor via calls to work(). The main thread assigns `threadIndex` to 0 in the same place:

Aha, looks like I misread the code. The `work()` calls are coming from within a lambda that's executed by the first created thread. So, right now, the main thread has the same threadIndex as the first spawned thread.

(But if that's the case, doesn't that cause a problem for the allocator? Doesn't the allocator require that the main thread has a different ID from the worker threads?)

Assuming it's okay for the main thread to alias the worker threads, what if we just check if the ThreadPoolExecutor has been constructed?

  // Parallel.h
  bool hasDefaultExecutor();
  unsigned getThreadIndex() {
    assert(hasDefaultExecutor());
    return threadIndex;
  }
  
  // Parallel.cpp
  static std::atomic<bool> HasDefaultExecutor = false;
  bool hasDefaultExecutor() {
    return HasDefaultExecutor;
  }
  
  Executor *Executor::getDefaultExecutor() {
    HasDefaultExecutor = true;


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142318/new/

https://reviews.llvm.org/D142318



More information about the llvm-commits mailing list