Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Program unexpectedly finished using C++11 thread
Forum Updated to NodeBB v4.3 + New Features

Program unexpectedly finished using C++11 thread

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 509 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Geng.Y
    wrote on last edited by
    #1

    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));
    
    G 1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

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

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      G 1 Reply Last reply
      0
      • dheerendraD dheerendra

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

        G Offline
        G Offline
        Geng.Y
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • G Geng.Y

          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));
          
          G Offline
          G Offline
          Geng.Y
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved