lundi 11 janvier 2016

C++: Multi-thread design when each thread is supposed to do both I/O and CPU intensive task

I have a situation where I am offloading my work to threads. The "work" compromises of two portions:

  • First compress the given data buffer
  • Then write the compressed data to disk

My main thread is continuously creating many data buffers.

I was initially thinking of a thread pool design, but then there could be a possibility that all my threads in the pool are waiting on I/O.

If I create a new thread whenever I create a new dataBuffer, I see that a large number of threads get created. This can then have overhead of content switching, but because of the context switch my CPU cycles are not getting wasted.

What can be a good design to manage this situations?

Aucun commentaire:

Enregistrer un commentaire