Hi all, in my application I need to use two different threads:
- The first thread only is executed one time, so, while it's running, the use can only abort it. I have implemented it with a boolean to know if the thread should abort the execution while it's running. This flag can be consulted by the thread while it's running and can be modified by a public method of the thread, all at the same time. I don't use any mutex while I make any of both operations but all works well. Anybody could tell me if it should be better if I use a mutex to lock this shared boolean variable when I consult/modify it?
- The second thread processes some files and can be executed various times. To make it I've thought in 2 different ways: the first ones consists in using a flag to know if the thread should restart in the case that the thread is running and doing QThread::wait at the end of every execution (if it's doesn't need to restart) until it's aborted. But, I've thougth to implement a simpler version that consists in: when the thread is running and the user wants to add more files at the list of the files that the thread is currently processing, I lock the list with a mutex and append the new files at the end of the list. The thread finnishes when it reaches the end of the list. If the user wants to process new files and the thread is finished, it starts again. So with this new version the thread is started everytime (if it's not running), but I don't need the flag to rerstart it and to do wait as on the other version. The question is: what's the best way to implement this last version: in the main bucle of the thread consulting everytime the value count of the list (locking it before with a mutex) to know if it has reached its end, using a Qlistiterator removing the files that has ben processed until the list is empty, or something else? Another question is what's the best way to handle this list of files: with a stringlist containing the path of the files to process or with a list of QFiles to know the path of the files??
Thanks
Bookmarks