title: Scheduling huge number of threads so only 4 are executed in parallel
body: <p>As already stated in the title I have a large number of threads (probably much higher than 100) that are rather saving a program state than running. I want only few of them (enough to use all physical processors) to really run concurrent and the rest should wait until one of the running is blocked. When this happens a new one should be running.</p>
  
  <p>Is it possible to achieve this with pthreads for example with the pthread scheduling functions? How would you do this?</p>
  
  <p>Regards,</p>
  
  <p>Nobody</p>
  
  <p><strong>EDIT</strong>
  More Information:
  Each thread fetches a job from the taskpool on its own and goes on to a certain point.
  I need 100 threads to gather at that certain point of program execution that cannot be calculated in parallel. When the calculation is done the threads should be awakened and go on. To make this efficient I have to avoid the scheduler from wasting time on switching between 100 threads instead of 4.</p>