AcademySoftwareFoundation / AcademySoftwareFoundation/openexr
Impossible to provide custom thread pool provider
- Dominant language
- C
- Stars
- 1.8k
- Forks
- 700
- Avg merge
- 3d 12h
- Merged PRs (30d)
- 29
Description
I tried to add a custom thread pool provider for OpenEXR (using the internal `DefaultThreadPoolProvider` as reference) via `IlmThread::ThreadPool::globalThreadPool().setThreadProvider()`. It seems that the provider should call `task->group()->_data->removeTask();` after executing the task. However, the definition of `IlmThread::TaskGroup::Data` is not provided, making it impossible to do this.
Is one expected to be able to customize OpenEXR like this by the application? If so, then I think some changes are needed in order to allow this.
For reference, here's the custom thread pool provider that I tried to use but it (expectedly) fails to compile on MSVC with:
``` error C2027: use of undefined type 'IlmThread_3_1::TaskGroup::Data'```
Complete source:
```
class TBBThreadProvider : public IlmThread::ThreadPoolProvider
{
public:
TBBThreadProvider() = default;
~TBBThreadProvider() noexcept override { finish(); }
int numThreads() const override { return myArena->max_concurrency(); }
void setNumThreads(int count) override
{
finish(); // TODO: Is this strictly needed?
myArena = std::make_unique(count);
}
void addTask(IlmThread::Task *task) override
{
myArena->execute([&]
{
myGroup.run([&]
{
task->execute();
task->group()->_data->removeTask();
delete task;
});
});
}
void finish () override
{
myArena->execute([&] { myGroup.wait(); });
}
private:
std::unique_ptr myArena = UTmakeUnique();
tbb::task_group myGroup;
};
```
Contributor guide
Research direction
Start with IlmThread::ThreadPool::globalThreadPool(), ThreadPoolProvider, TaskGroup::Data, and the internal DefaultThreadPoolProvider used as the reference. Determine whether application-supplied providers are supported and what public task-completion API is required; done means the intended customization path is defined and the supplied provider can compile and manage task completion on MSVC.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100