Who can that will prompt as to organize ThreadPool? I shall be glad to examples. It is necessary to set the maximal size of a pool, to operate streams (start, end of a stream)
Who can that will prompt as to organize ThreadPool? I shall be glad to examples. It is necessary to set the maximal size of a pool, to operate streams (start, end of a stream)
I don't entirely understand what you want, but if you want to have a thread pool, you'll need a wait condition that will start or stop threads from within a pool and an array of thread objects. If you want something more advanced, a controller spawning and destroying threads should be implemented as well. Trying QtConcurrent (available at labs.trolltech.com) might be a good idea as well.
I need to store the list of the started processes (or them ID). During work I should have an opportunity at any moment to finish process.
QThread !
I think to use QList for this purpose:
create :
Qt Code:
QList<CWorkThread*> threadList; if( threadList.size() < 4) { CWorkThread *thread = new CWorkThread(this); threadList.append(thread); thread->run(); }To copy to clipboard, switch view to plain text mode
and for terminate:
Whether there will be it the correct decision???Qt Code:
for(int i = 0; i < threadList.size(); i++) { CWorkThread *nb = threadList.at(i); nb->terminate(); nb->wait(); threadList.erase(threadList.begin()+i); i--; }To copy to clipboard, switch view to plain text mode
First of all you should never use terminate() unless you know what you are doing. Second of all I don't see any "pool" here, just a bunch of threads. I think you should just let all threads do their job and connect to each thread's finished() signal and delete the thread when it's done doing whatever it was doing.
I shall think above that that you have told. But in me can be caused 4-5 threads for copying files in the size 10-80 Gb, and there should be an opportunity to stop copying. There are other ways of the decision?
Yes, you could tell the thread to stop.
The most common way is to add a volatile boolean flag in the thread and a setter.
When you set this flag to true(from outside the thread) it means the thread should stop. You have to test for this flag in the thread in all extensive operations.
For example, if you copy the files in a loop, then you should test that flag and break the loop when it is false.
Regards
Bookmarks