The best way is probably to spawn a pool of image conversion worker threads. You also create a thread-safe queue of conversion requests. The main thread will read image names and place the conversion requests in the queue. The worker threads will remove conversion requests from the queue and carry out the conversions.
When all the images have been queued, place special commands on the queue which tell the worker threads to terminate. Then join with all the worker threads.
Pseudocode:
Code:
imageQueue = Queue()
workerThreads = []
for n in range(0, numThreads):
workerThreads.append( SpawnThread( WorkerThread, imageQueue ) )
for img in images:
imageQueue.Enqueue( img )
for n in range(0, numThreads):
imageQueue.Enqueue( QuitCommand )
for n in range(0, numThreads):
Join( workerThreads[n] )
def WorkerThread( imageQueue ):
while True:
command = imageQueue.Dequeue()
if command is QuitCommand:
break
ConvertImage( command )