Dear colleagues
I am programming an application which starts a lot of threads for some
calculations. The problem that I have is that when I start up to 100 threads
then everything works fine. Depending of number of jobs it might be that
sometimes application need to start up to 4000 threads for this small jobs.
You see probably already the problem. This is not good idea to start 5000
threads at the same time (memory).
My idea is to have a function which controls the current number of working
threads. I would like to have something like 100 threads in the memory at
one time and the rest must be waiting or might not be even initiated. Once a
thread is finished the function should take one waiting job and start it
with a new thread.
Is it possible for example to control this with Mutex. e.g. to define the
muttex to 100. Up 100 the mutex let's the procedure waiting. Once a mutex is
released and somehow internally the mutex has value of 99 the new muttex may
increase the muttex to 100. The next one can't increase because the muttex
is limited to 100. So he waits until muttex has valu under 100 end so on.
If this is not possible, do you have other ideas?
THANKS ALEX SIMIC