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. QMutex and unique_lock ?
Forum Updated to NodeBB v4.3 + New Features

QMutex and unique_lock ?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.7k Views 2 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #1

    I'm replacing mutex references in a project previously using boost for:

    boost::mutex and boost::recursive_mutex
    

    There are also several instances using:

    std::unique_lock<boost::mutex> lock(&mutex);
    

    https://en.cppreference.com/w/cpp/thread/unique_lock

    Is there an equivalent implementation for achieving the same using a QMutex ?

    Kind Regards,
    Sy

    jsulmJ 1 Reply Last reply
    0
    • SPlattenS SPlatten

      I'm replacing mutex references in a project previously using boost for:

      boost::mutex and boost::recursive_mutex
      

      There are also several instances using:

      std::unique_lock<boost::mutex> lock(&mutex);
      

      https://en.cppreference.com/w/cpp/thread/unique_lock

      Is there an equivalent implementation for achieving the same using a QMutex ?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @SPlatten https://doc.qt.io/qt-5/qmutexlocker.html

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      SPlattenS 1 Reply Last reply
      2
      • jsulmJ jsulm

        @SPlatten https://doc.qt.io/qt-5/qmutexlocker.html

        SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on last edited by
        #3

        @jsulm , I see what there are references to recursive, but no reference to unique anywhere.

        Kind Regards,
        Sy

        JKSHJ 1 Reply Last reply
        0
        • SPlattenS SPlatten

          @jsulm , I see what there are references to recursive, but no reference to unique anywhere.

          JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by JKSH
          #4

          @SPlatten said in QMutex and unique_lock ?:

          I see what there are references to recursive, but no reference to unique anywhere.

          Don't get hung up on the name. https://en.cppreference.com/w/cpp/thread/unique_lock has no reference to "unique" anywhere either (except for the name of the class)!

          • A std::unique_lock is simply a std::lock_guard that can be unlocked/relocked.
          • A QMutexLocker is like a std::lock_guard that can be unlocked/relocked.

          Just use QMutexLocker the same way you'd use std::unique_lock.

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          SPlattenS 1 Reply Last reply
          2
          • JKSHJ JKSH

            @SPlatten said in QMutex and unique_lock ?:

            I see what there are references to recursive, but no reference to unique anywhere.

            Don't get hung up on the name. https://en.cppreference.com/w/cpp/thread/unique_lock has no reference to "unique" anywhere either (except for the name of the class)!

            • A std::unique_lock is simply a std::lock_guard that can be unlocked/relocked.
            • A QMutexLocker is like a std::lock_guard that can be unlocked/relocked.

            Just use QMutexLocker the same way you'd use std::unique_lock.

            SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by
            #5

            @JKSH Thanks

            Kind Regards,
            Sy

            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