fix tread pool crashed

This commit is contained in:
Andrei Yankovich 2019-08-06 15:55:50 +03:00
parent 1093323f64
commit 4abcd137bf
2 changed files with 14 additions and 5 deletions

View File

@ -48,10 +48,15 @@ void KeysReactor::handleGenerateNewKeys() {
return; return;
}; };
QtConcurrent::run(generatorFunc, QRSAEncryption::RSA_64); _futures.insert(QRSAEncryption::RSA_64,
QtConcurrent::run(generatorFunc, QRSAEncryption::RSA_128); QtConcurrent::run(generatorFunc, QRSAEncryption::RSA_64));
QtConcurrent::run(generatorFunc, QRSAEncryption::RSA_256); _futures.insert(QRSAEncryption::RSA_128,
QtConcurrent::run(generatorFunc, QRSAEncryption::RSA_512); QtConcurrent::run(generatorFunc, QRSAEncryption::RSA_128));
_futures.insert(QRSAEncryption::RSA_256,
QtConcurrent::run(generatorFunc, QRSAEncryption::RSA_256));
_futures.insert(QRSAEncryption::RSA_512,
QtConcurrent::run(generatorFunc, QRSAEncryption::RSA_512));
} }
@ -77,5 +82,8 @@ KeysReactor::KeysReactor(bool ForceGenerateKey, QObject *ptr):
} }
KeysReactor::~KeysReactor() { KeysReactor::~KeysReactor() {
for (auto && i: _futures) {
i.cancel();
i.waitForFinished();
}
} }

View File

@ -15,6 +15,7 @@ private:
ClientProtocol::RSAKeysPool _pool; ClientProtocol::RSAKeysPool _pool;
int _poolSize = DEFAULT_KEYPOOL_SIZE; int _poolSize = DEFAULT_KEYPOOL_SIZE;
QHash<QRSAEncryption::Rsa, bool> _mutexs; QHash<QRSAEncryption::Rsa, bool> _mutexs;
QHash<QRSAEncryption::Rsa, QFuture<void>> _futures;
void generateKeys(QRSAEncryption::Rsa); void generateKeys(QRSAEncryption::Rsa);
private slots: private slots: