Dear all,

I'd like to ask you a very simple question concerning multi-threading via the QtConcurrent framework.

I'm a complete beginner when it comes to multi-threading. Anyhow, since in one of the application I'm working on right now using more than one thread would be dramatically useful, I've decided to give a try to the QtConcurrent framework.

Could you please tell me if, in your opinion, the few lines of code below, wrote after reading the short tutorials found on the Qt's website, make sense? What I'm trying to do here (of course assuming that PARALLEL_CALCULATIONS has been defined) is to run POPULATION_SIZE instances of the function teams->simTeam[currentTeam]->performAllTests(), each of those inside a separate thread.

Qt Code:
  1. for (currentTeam = 0; currentTeam < POPULATION_SIZE; currentTeam++) {
  2.  
  3. // Evaluate the current team using exploiting or not concurrent programming
  4. #ifdef PARALLEL_CALCULATIONS
  5. synchronizer.addFuture(QtConcurrent::run(teams->simTeam[currentTeam], &Team::performAllTests));
  6. #else
  7. teams->simTeam[currentTeam]->performAllTests();
  8. #endif
  9.  
  10. }
  11.  
  12. // Wait until the last thread has ended its execution before moving to the next generation (if parallelized)
  13. #ifdef PARALLEL_CALCULATIONS
  14. synchronizer.waitForFinished();
  15. #endif
To copy to clipboard, switch view to plain text mode 

Then, I use the synchronizer.waitForFinished() instruction in order to make the program waiting until the execution of all the threads is finished.

Please also consider that the code above is contained inside another for-cycle. Maybe I also need to clear the synchronizer before using it again?

Many thanks to anybody willing to waste his time helping me...

Fabio