Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Threading in Linux and MacOS
Forum Updated to NodeBB v4.3 + New Features

Threading in Linux and MacOS

Scheduled Pinned Locked Moved C++ Gurus
5 Posts 5 Posters 3.6k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    apollo74
    wrote on last edited by
    #1

    I'm having some strange behavior of my application and I really need some help. My app computes an algorithm and a opengl widget plots the result of that algorithm. The result is a vector of pointers to float (std::vector<float*> result), so I'm plotting several functions at the same time in XY coordinates. In the MainWindow.cpp I am using:

    @
    uiPlot->plotStart(); //Shows the opengl widget and starts a QTimer.
    runThread = QtConcurrent::run(this,&MainWindow::mainLoop);
    runWatcher.setFuture(runThread);
    @

    where runThread is a QFuture<void> object and runWatcher is a QFutureWatcher<void> object. The class uiPlot is a Dialog that contains a QGLWidget object where I plot all my functions and it contains also a QTimer that updates the plotting every "fps" frames per second. The mainLoop function has an endless loop that computes the vectors and also a delay using QWaitCondition:

    @
    while(1){
    computeAll( input ); //Updates the content of all vectors in "result".

    mutex.lock();
    waitCondition.wait(&mutex, 1000/fps);
    mutex.unlock();
    

    }
    uiPlot->plotStop(); // Stops the timer and closes the widget.
    @

    My problem: I don't understand why the application works fine if I want to plot a single function (result.size() = 1) but crashes when I want to plot several functions at the same time(result.size() > 1)... this is only in Linux because it works for any sizes in MacOS. One more mysterious thing, if I debug the application everything works fine in Linux, it is only when I'm running it (without debugging) when it crashes.

    Any help will be very much appreciated,

    B

    1 Reply Last reply
    0
    • L Offline
      L Offline
      loladiro
      wrote on last edited by
      #2

      Sounds to me like you have timing issues somewhere.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Santosh Reddy
        wrote on last edited by
        #3

        I guess you problem is with threads, std::vector<T> is not implicitly shared, user QVector<T> instead it is implicitly shared, it can work across threads.

        SS

        1 Reply Last reply
        0
        • F Offline
          F Offline
          Franzk
          wrote on last edited by
          #4

          [quote author="Santosh Reddy" date="1308202268"]I guess you problem is with threads, std::vector<T> is not implicitly shared, user QVector<T> instead it is implicitly shared, it can work across threads.[/quote]That does depend on how you use it. If you have multiple threads accessing the same instance of the vector, implicit sharing won't help you. But when taking the approach of creating and filling a container and then copying the contents to a shared location, it certainly will.

          "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • W Offline
            W Offline
            wongk
            wrote on last edited by
            #5

            QVector is not threadsafe, and neither is std::vector. If you have a shared resource, accesses to it must be serialized.

            Another question, why are you using a pointer to a float rather than just a float in your vector? You are not using any less memory.

            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