[fpc-devel] Light weight threads for FPC

Marco van de Voort marcov at stack.nl
Fri Dec 14 16:18:52 CET 2007

> > > You still can implement such thread pools on top of OpenMP(I) (or 
> > > similar APIs), if you need to get much lighter. ;)
> > 
> > Afaik there are threadpool classes in Indy, and they work. 
> Thanks. I will take a look.

Please keep me informed, I'll have to do something like this soon too.
(though for now windows only). I did some thinking and have some urls. he
most importnant one for Windows can be found if you search for "Martin
Harvey" + threading faq (or threads faq) for primitives.

For me the calculated results also need to be retired (reconstructed), and
the task queue needs to be fifo.

My initial scheme is a bit like this:

Some points:

- the producer threads produce pieces of data, (20-40 /s typically.)
   total data (image) production rate 20-100MB/s (mbytes that is)
   With this scheme I hope to further increase this (e.g. 150-200MB/s tops)
- each datum is possibly splitted 2,3,4 way before being passed on to the
  calculation part.  The splitting is governed by symmetry concerns (for 
  easy joining) and a target of about 5-20ms of calculation time. The
  calculation time is not entirely constant but it has to cope well with the 
  worst case situation and be decent with the typical situation.
- A very small part of the calculation is not paralellisable, and has to be
  done when all parts are calculated. (in pic shown as the collection thread,
  which keeps track if the parts of a data packed are all calculated, and then
  does the final calculation) 
- Probably some of the final results need to go to the mainthread for
  displaying and serial I/O. (I use TComport atm, which is meant for the
  mainthread t.b.d.)
- Threads is the amount of free cores. Since the production threads also
  copy the data (which is already good for 10% cpu at these datarates) I'm
  thinking about using the cheapest (read: coolest) Core 2 quad core and
  have 3 worker threads operating maximally, and keep the other core free
  for the copying. (bind if necessary).

Main problem is how to efficiently implement the dispatching of tasks and
retiring them. I still need to take time to figure this out.

More information about the fpc-devel mailing list