PDA

View Full Version : External libary in a separate thread: is this correct?



sylvaticus
3rd December 2009, 08:33
I have a crash in an external mathematical library when I use it from a separate thread than the main one, while it works perfectly if I call it from the main thread.
I know this library is not multi-thread, but it is used in a sequential way using a single thread. Neverless it crashs when comparing the time elapsed using CPU clocks.
Can someone explain me why this code is wrong, or if you think it is a bug in the external library or in the qt thread library?
Attached there is a complete compilable (small) example, but the core of the code is:


int main(int argc, char *argv[]){

cout << "Test on a glpk application using Qt Threads" << endl<<endl;
Thread wThread; // subclass QThread just for the run() method.
for (uint y=0;y<5000;y++){
wThread.start(); // just calls the glpk simple documentation example
wThread.wait();
}
cout <<"All done without errors (crashing)"<<endl;
return 0;
}

wysota
3rd December 2009, 08:47
Please don't start multiple threads on the same subject.

http://www.qtcentre.org/forum/f-qt-programming-2/t-qmutex-seems-not-to-lock-22171.html