PDA

View Full Version : Best way to coordinate two threads?



qlands
1st April 2012, 13:02
Hi,

I working in a program that inserts a massive file into a database. I want to separate the program in two threads:

1. The first thread process and separates the massive file into several files.

2. The second thread should wait for a portion of the file created by thread 1 and insert it into the database.

I want to separate the processing of the massive file into two concurrent processes that could process and insert the massive file at the same time, so It takes less time.

What would it be the best way to coordinate the two threads? Signals and Slots?

Thanks,
Carlos.

wysota
1st April 2012, 14:51
The simplest solution is to use QMutex with QWaitCondition or QSemaphore. You have a classic producer-consumer pattern here.