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

Alexey Lapshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 14 04:43:36 PDT 2023


avl added a comment.

In D142318#4266443 <https://reviews.llvm.org/D142318#4266443>, @MaskRay wrote:

> When a `llvm::parallel::parallel_*` function returns, the ThreadPoolExecutor doesn't reset `llvm::parallel::threadIndex`. So the check won't be effective for a `PerThreadBumpPtrAllocator` misuse after a `parallel_*` function call.

If it would not catch all the cases, probably it still would be useful if catch some of them.
f.e. following case would be coaght:

  PerThreadBumpPtrAllocator Allocator;
  
  parallelFor() {
     Allocator.Allocate();
  }
  
  Allocator.Allocate();   << the call is done on main thread.
                          << assertion should be raised.
   



  PerThreadBumpPtrAllocator Allocator;
  ThreadPool Pool(parallel::strategy);
  Pool.async([&]() { Allocator.Allocate(); });  << the call is done on the thread created by not ThreadPoolExecutor. 
                                                << assertion should be raised.

Can it be useful?

It also could probably be done in more general way:

  #if LLVM_ENABLE_ASSERTIONS
  thread_local unsigned threadIndex = -1;
  #else
  thread_local unsigned threadIndex;
  #endif
  inline unsigned getThreadIndex() { 
    assert(threadIndex != -1);
    return threadIndex;
  }


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