title: Multithreaded image processing in C++
body: <p>I am working on a program which manipulates images of different sizes.  Many of these manipulations read pixel data from an input and write to a separate output (e.g. blur).  This is done on a per-pixel basis.</p>
  
  <p>Such image mapulations are very stressful on the CPU.  I would like to use multithreading to speed things up.  How would I do this?  I was thinking of creating one thread per row of pixels.</p>
  
  <p>I have several requirements:</p>
  
  <ul>
  <li>Executable size must be minimized.  In other words, I can't use massive libraries.  What's the most light-weight, portable threading library for C/C++?</li>
  <li>Executable size must be minimized.  I was thinking of having a function forEachRow(fp* ) which runs a thread for each row, or even a forEachPixel(fp* ) where fp operates on a single pixel in its own thread.  Which is best?
  
  <ul>
  <li>Should I use normal functions or functors or functionoids or some lambda functions or ... something else?</li>
  <li>Some operations use optimizations which require information from the previous pixel processed.  This makes forEachRow favorable.  Would using forEachPixel be better even considering this?</li>
  </ul></li>
  <li>Would I need to lock my read-only and write-only arrays?
  
  <ul>
  <li>The input is only read from, but many operations require input from more than one pixel in the array.</li>
  <li>The ouput is only written once per pixel.</li>
  </ul></li>
  <li>Speed is also important (of course), but optimize executable size takes precedence.</li>
  </ul>
  
  <p>Thanks.</p>
  
  <p><strong>More information on this topic for the curious: <a href="https://stackoverflow.com/questions/615264/c-parallelization-libraries-openmp-vs-thread-building-blocks">C++ Parallelization Libraries: OpenMP vs. Thread Building Blocks</a></strong></p>