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. Question regarding Mandelbrot threading Example
Forum Updated to NodeBB v4.3 + New Features

Question regarding Mandelbrot threading Example

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.8k 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.
  • J Offline
    J Offline
    justDance
    wrote on last edited by
    #1

    Hi all,

    I have two questions about Mandelbrot threading Example (http://doc.qt.digia.com/main-snapshot/threads-mandelbrot.html)

    1. I implemented a thread similar to RenderThread. when I step in my code, I noticed that after thread wake up, it is extremely slow stepping from the last line of code to the first line of code inside run() forever loop. The last two lines of code in run() forever loop are:
      restart = false;
      mutex.unlock();
      the first line of code in run() forever loop is
      mutex.lock();

    why is it so slow, is it related to forever?

    1. who will call RenderThread::~RenderThread(), it is now shown in the example? more general question is how to delete a worker thread.

    Thanks,

    1 Reply Last reply
    0
    • K Offline
      K Offline
      KA51O
      wrote on last edited by
      #2

      To delete a QThread you usually do something like this:
      @
      connect(myThread, SIGNAL(finished()), myThread, SLOT(deleteLater()));
      @

      1 Reply Last reply
      0
      • J Offline
        J Offline
        justDance
        wrote on last edited by
        #3

        sorry, I didn't make my question clear. in Mandelbrot threading Example, main thread can just call ~RenderThread() to destroy this thread since run() is checking abort flag.
        KA510's signal-slot connection seems only for self destruction. how can I delete worker thread from main thread if the worker thread's run() is only calling exec(), there is no flag checking there?

        1 Reply Last reply
        0
        • K Offline
          K Offline
          KA51O
          wrote on last edited by
          #4

          That depends on the approach you're using. If you are using the "worker object approach":http://qt-project.org/wiki/QThreads_general_usage, or if you're using the old subclassing approach (which you should avoid in most cases). If you have a look at the example code provided in the article on the general usage of QThread (see link above) I think your problem should resolve itself. If you have more questions I'll be glad to try and help you.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            justDance
            wrote on last edited by
            #5

            Another question is in this example we put thread into sleep when it is not used. Another option is to delete the thread, then recreate and run a new thread when it is needed.
            Personally I prefer the sleep option since I think thread deletion/creation is more expensive, but I did see thread deletion/creation examples some other places. Is there any experiment to prove which one is better? I don't know how to use profiler to check the two options.

            Thanks,

            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