Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
5.0.1, 6.0.1
-
None
-
Windows
Qt 5, Qt 6, both tested
VS2019
MinGW 11.2
Description
Seems like data race for lambda with Qt::QueuedConnection
env:
- Windows
- Qt 5, Qt 6, both tested
- VS2019
- MinGW 11.2
Lets take a look at code snippet:
void Controller::doWork() { for (size_t ix = 0; ix < 2; ++ix) { QObject* ctx = new QObject; QObject::connect(this, &Controller::finished, ctx, [this, ctx] (QString id) { this->disconnect(ctx); ctx->deleteLater(); qDebug() << "Received value " << ctx << " :"; qDebug() << id; }, Qt::QueuedConnection); qDebug() << "Passed value: " << QString::number(ix); work(QString::number(ix)); } } void Controller::work(QString id) { [[maybe_unused]] auto future = QtConcurrent::run([this, id] () { qDebug() << "Replied: " << id; QThread::msleep(300); emit finished(id); }); }
EB:
- lambda was called twice (see attachment)
AB:
- lambda was called 4 times, sometimes twice (see attachment)
Minimal sample to test in attach.
Detailed descrition.
- In my main project i had issue that on such call i got EB from above. But, second call was with cached arguments from first call arguments.
Example output:
Passed value: "0"
Passed value: "1"
Replied: "0"
Replied: "1"
Received value "0"
Received value "0" - I tried to reproduce argument caching on this code snippet, but i couldn`t, while i could steel reproduce it in main project env.
- I could not reproduce AB in main project env while code architecture literally same.