I want to run multiple MuparserX parsers concurrently using QThreadPool. Here's the code:
#include <iostream>
#include <QRunnable>
#include <QThreadPool>
#include "mpParser.h"
struct Task: public QRunnable {
void run() override {
//Create a new parser
mup::ParserX p;
}
};
int main(int argc, char *argv[])
{
for (int i = 0; i != 10; ++i)
QThreadPool::globalInstance()->start(new Task);
while (QThreadPool::globalInstance()->activeThreadCount() > 0) {}
return 0;
}
However, my program crashes with either "list iterators incompatible" or "list iterator not dereferencable" errors in the destructor mup::ParserX::~ParserX()
. This happens only with MSVC13 and 15, and only in debug builds; release builds run without error and produce the expected output. GCC debug and release builds both work fine. Is there some nuance of Microsoft's compiler that's causing this, or is my program incorrect?