I'm about to release a new version of one of my softwares which is a GUI frontend for UPX. The new capability is multithreaded compression. Upon releasing, I look into the multithreading code again and not really sure about the design, so I recode that part but now I got confused. Both seems incorrect for me, there must be a better way.
In design 1, the main thread creates other threads and then loop until all items are processed (number of currently finished item is given to each thread, shared and protected inside critical section). Inside the loop, I put Application.ProcessMessages; followed by Sleep(100); to give some time so the main application doesn't hang too much. The main thread also updates a progress bar during (and after) the loop. Other threads update their corresponding line in a TListView (through synchronize method).
In design 2, there's another thread helper that creates other threads, and updates the progress bar (through synchronize method). The execute method of this thread is more or less equal to main thread code in design 1 (i.e. the while loop) but without Application.ProcessMessages or Sleep call because I assume since it's implemented in a thread, it won't hang the main thread. Other threads still do the same, update their corresponding line in a TListView. When all items have been processed, the helper thread enables GUI controls and terminate. In this design, the main thread does nothing but creating the helper thread.
In both design, main thread disables GUI controls before doing any of the above steps.
Which do you think is better? Or if both are wrong, what's your suggestion? I attach both projects if you need to inspect the code. Sorry, I didn't include UPX executable because it's too big to fit as attachment.