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. Use independent resource for each thread in the QThreadPool

Use independent resource for each thread in the QThreadPool

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 679 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.
  • S Offline
    S Offline
    stereomatching
    wrote on last edited by
    #1

    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
    0

    • Login

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