-
Notifications
You must be signed in to change notification settings - Fork 700
Open
Description
I noticed that the thread callback routine may be called recursively. This is problematic when using a simple thread_pool that accepts jobs in a FIFO order. It deadlocks because it is waiting on a task that cannot be executed yet.
My code is currently
fftwf_init_threads();
fftwf_plan_with_nthreads(static_cast<int>(workers.max_concurrency()));
fftwf_threads_set_callback(
[](void *(*work)(char*), char* jobdata, size_t elsize, int njobs, void* workers)
{
signaling_counter counter{static_cast<size_t>(njobs)};
auto& obj = *static_cast<thread_pool_type*>(workers);
for (int i = 0; i < njobs; ++i)
{
obj.submit(
[work, jobdata, elsize, i, &counter = counter.get_state()]{
work(jobdata + elsize * i);
counter.decrement();
}
);
}
counter.wait();
},
&workers
);What is the approach I should take to avoid deadlock?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels