-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
basically I was just profiling to see how many empty jobs can be scheduled every frame to get idea of average overhead.. and it happened that the queue incurs in deadlocks! The following code reproduce the error on my machine (you just need to play with number of threads in pool and initial recursive depth, the deadlock will necessarily occurs first or later.)
In the few cases in wich following code didn't deadlocked it required ~200 ms (2x2Ghz cores) so 5000 jobs per second is actual throughput if you remove the deadlock.
void recursiveWork(ThreadPool & pool, int depth){
if (depth<=0)
return;
auto result = pool.enqueue( {return 1;}); //empty job.. apparently the formatting remove some parentheses
//here, I'm just passing a lambda that returns 1 by the way
recursiveWork(pool, depth-1);
result.get();
}
int main(){
ThreadPool pool(4);
for (int i= 0; i<1000; i++){
recursiveWork(pool,4);
}
return 0;
}