Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Program unexpectedly finished using C++11 thread



  • Hi, I have encounter an issue that when I added C++ thread, program has unexpectedly finished.
    To begin with, I call the drawObject(it); iteratively to draw 9 objects, and it works fine. When I tried to use multithreading to complete this task, the process was ended forcefully.

        std::vector<std::thread> threads;
        int i = 1;
        for (auto it : solarSystem->getObjects()){
    
            if (it->visiblity()){
                glBindTexture(GL_TEXTURE_2D, texture[i]);
                threads.push_back(std::thread(drawObject,it));
    //            drawObject(it);
            }
    
            i++;
        }
        for_each(threads.begin(), threads.end(), mem_fn(&std::thread::join));
    

  • Qt Champions 2017

    what is drawObject doing ? Are you doing something with UI here ? Are you creating some widgets there ?



  • @dheerendra drawObject is to draw a planet on QGLWidget. This part of code is inserted in paintGL().



  • Now I tried this code on Ubuntu 18.04, the program can run but don't get the result before using threading. (Nothing drew).


Log in to reply