Move function-scope static QThreadStorage objects to namespace scope

to ensure destruction after all function-scope statics and avoid warning
"thread exited after QThreadStorage destroyed".
This commit is contained in:
Mat Sutcliffe
2019-01-05 16:49:20 +00:00
parent 1493106970
commit e7582f2f3c
4 changed files with 9 additions and 4 deletions

View File

@@ -50,6 +50,9 @@ namespace BlackMisc
//! \threadsafe
inline std::mt19937 &defaultRandomGenerator()
{
//! \fixme Move rng to namespace scope to ensure destruction after function-local statics
//! and avoid warning "thread exited after QThreadStorage destroyed".
//! This will require careful thought about linkage.
static QThreadStorage<std::mt19937> rng;
if (rng.hasLocalData()) { rng.setLocalData(std::mt19937(static_cast<std::mt19937::result_type>(QRandomGenerator::global()->generate()))); }
return rng.localData();