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. QMutexLocker - locking question
Forum Updated to NodeBB v4.3 + New Features

QMutexLocker - locking question

Scheduled Pinned Locked Moved Unsolved General and Desktop
qmutexqmutexlocker
5 Posts 3 Posters 935 Views
  • 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.
  • D Offline
    D Offline
    Dariusz
    wrote on 2 Jan 2020, 10:54 last edited by
    #1

    Hey

    So I have a QMutexLocker l(&mLock);

    When this function gets called and mLock is already locked by another thread. What happens?

    1. The program stops & try-lock/wait forever until he can access the mutex to lock it?
    2. The program stops and does nothing.

    I'm trying to debug app locks :- )

    TIA!

    J 1 Reply Last reply 2 Jan 2020, 11:06
    0
    • D Dariusz
      2 Jan 2020, 10:54

      Hey

      So I have a QMutexLocker l(&mLock);

      When this function gets called and mLock is already locked by another thread. What happens?

      1. The program stops & try-lock/wait forever until he can access the mutex to lock it?
      2. The program stops and does nothing.

      I'm trying to debug app locks :- )

      TIA!

      J Offline
      J Offline
      JonB
      wrote on 2 Jan 2020, 11:06 last edited by
      #2

      @Dariusz
      I assume it does as per QMutextLocker::lock(), i.e. block and wait.

      1 Reply Last reply
      2
      • D Offline
        D Offline
        Dariusz
        wrote on 2 Jan 2020, 11:33 last edited by
        #3

        So if its already locked, then it waits? Will it try again locking or its just in waiting mode?

        J 1 Reply Last reply 2 Jan 2020, 12:03
        0
        • D Dariusz
          2 Jan 2020, 11:33

          So if its already locked, then it waits? Will it try again locking or its just in waiting mode?

          J Offline
          J Offline
          JonB
          wrote on 2 Jan 2020, 12:03 last edited by
          #4

          @Dariusz
          I believe it will block/wait and then lock and continue as & when the mutex gets unlocked. But you should test.

          1 Reply Last reply
          3
          • C Offline
            C Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 2 Jan 2020, 16:04 last edited by
            #5

            @Dariusz said in QMutexLocker - locking question:

            So if its already locked, then it waits?

            This is exactly what a mutex is build for...

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            3

            5/5

            2 Jan 2020, 16:04

            • Login

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