Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Use independent resource for each thread in the QThreadPool

    General and Desktop
    1
    1
    562
    Loading More Posts
    • 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.
    • S
      stereomatching last edited by

      Assume I am processing a bunch of heavy data(1000 of them) by QtConcurrent::mapped

      @auto result = QtConcurrent::mapped(image_id, std::bind<std::pair<QString, QImage>>(&mainWindow::process_image_impl, this, ph::1));
      image_sequence
      .setFuture(result);@

      instead of

      @void process_image_impl(int image_id)
      {
      //.......lots of codes

      {
      QMutexLocker locker(&mutex);
      morphology.close(image, image); //I don't want to lock this operation
      }

      //lots of codes
      }@

      I would like to do something like

      @void process_image_impl(int image_id)
      {
      //.......lots of codes

      morphology[thread_id].close(image, image); //I don't want to lock this operation
      

      //lots of codes
      }@

      in the function process_image_impl, I have a class called "morphology", I don't want to lock the class
      "morphology" when I process the image, but if I don't lock it I may cause undefined behavior.Instead
      of locking the process, I would like to put the class "morphology" in a container and call each
      of the "morphology" according to the thread in the QThreadPool, is this possible?Or do you have
      other suggestions?Thanks

      ps : it is unrealistic to create 1000 copy of "morphology"

      1 Reply Last reply Reply Quote 0
      • First post
        Last post