I have a for loop that reads an image, converts it, and then writes it to disk. This loop runs in its own thread, and it works fine. However, I would like split this up so I can run this loop in say, the main thread and then spawn multiple threads to do the dirty work. This way, I can use multiple CPU cores to convert the images (since it would then be able to process as many images simultaneously as the number of cores in the machine).
I am not quite sure what the best way is to do this. Should I create the loop in the main/separate thread, then spawn threads inside the loop up to the maximum number of CPU cores? What would be the best way to keep track of how many threads were already running? Just set a var that is incremented upon the thread starting, then decremented when it finishes, locking the latest thread if the max number of threads are already running?
Thanks for any help!