I’m running a pthreads program that works very nicely, however I don’t see the speedup I would expect. I suspect that I spend to much time creating and destroying my threads.
I’m at no time running more threads than I have cpus.
Over a period of 20 minutes I’m creating a approximately 5000 threads.
My question is if it’s worthwhile implementing a proper static work pool, such that I will only allocate a static number of workers?
First you should measure where your app is spending all of it’s time. That comes out to about 4 or 5 thread creations per second, which is a lot but probably not where you’re spending all of your time.
That said, however, if you’re always limiting yourself to N threads, where N is the number of CPUs, the you should probably just create N threads up front and schedule work to run on each thread using some algorithm that makes sense wrt the calculation you’re doing.