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

Alexey Lapshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 23 15:15:02 PST 2023


avl added a comment.

In D142318#4074207 <https://reviews.llvm.org/D142318#4074207>, @steven_wu wrote:

> I agree that this probably doesn't work for CAS since the use of CAS is not bounded to any context like a ThreadPoolExecutor, for example, it is currently a legal use case to have multiple thread pool to insert into CAS at the same time. It is not feasible to put such a restriction on CAS since CAS should be safe to read/write concurrently from different process.
>
> For this PoolAllocator, it might be a good idea to require it to be initialized with an instance of `ThreadPoolExecutor` and maybe add a method for Thread to get the context of its Executor so you can double check the allocator is used in the correct Exectuor when assertion is on.

I see, My first intention was to implement some similar solution.  But it requires an additional refactoring(f.e. ThreadPoolExecutor is not currently visible). This patch is simple working implementation allowing to check the idea.

I was thinking about something like that:

  class ThreadPoolAllocator {
    void *Allocate(size_t size, size_t alignment);
  };
  
  class ThreadPool {
    std::unique_ptr<ThreadPoolAllocator> getAllocator ();
  };
  
  class ThreadPoolExecutor {
    std::unique_ptr<ThreadPoolAllocator> getAllocator ();
  };




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