Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. when QMutex block my program ? when this thing will happen ?
Qt 6.11 is out! See what's new in the release blog

when QMutex block my program ? when this thing will happen ?

Scheduled Pinned Locked Moved Solved Mobile and Embedded
7 Posts 3 Posters 1.7k 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.
  • Q Offline
    Q Offline
    Qt embedded developer
    wrote on last edited by Qt embedded developer
    #1

    when QMutex freeze the qt application ?

    please give me solution for it ?

    jsulmJ 1 Reply Last reply
    0
    • Q Qt embedded developer

      @jsulm

      i have written one function which get accessed in thread at every 500 ms and same function i have accessed outside this thread . so some time dead lock situation get created. now to avoid that situation i want to use QMutex.

      But i does not have much knowledge regarding where i need to use Qmutex lock and unlock .

      I have seen that mutex lock and unlock some times freeze application.

      So i need description in which scenario of Qmutex lock and unlock function freeze application?

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #7

      @Qt-embedded-developer
      There is not much to explain. If two threads both execute a QMutex lock on the same resource, then the second arrival one will sleep/block until the first arrival releases the lock. So if the non-UI thread is holding a lock and has not released it, the main UI thread will block --- and be unresponsive --- until the secondary thread releases it.

      It therefore behoves you to ensure you lock the minimum amount of code which is safe, and have a thread which holds a lock complete whatever it needs to do as fast as possible.

      There is no "magic workaround" for this. If the two threads in question genuinely each need to hold a lock then that is how it is, the second one cannot proceed safely until the first one is done.

      1 Reply Last reply
      2
      • Q Qt embedded developer

        when QMutex freeze the qt application ?

        please give me solution for it ?

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

        @Qt-embedded-developer said in when QMutex block my program ? when this thing will happen ?:

        this function

        I don't see any mutexes in this function...

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

        Q 1 Reply Last reply
        0
        • jsulmJ jsulm

          @Qt-embedded-developer said in when QMutex block my program ? when this thing will happen ?:

          this function

          I don't see any mutexes in this function...

          Q Offline
          Q Offline
          Qt embedded developer
          wrote on last edited by
          #3

          @jsulm Hi

          i have changed my question's description. i want to know where we must not use QMutex ?

          jsulmJ 1 Reply Last reply
          0
          • Q Qt embedded developer

            @jsulm Hi

            i have changed my question's description. i want to know where we must not use QMutex ?

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

            @Qt-embedded-developer The correct question is: where do I have to use a mutex? If QMutex freezes your app that means that you have a dead lock. But without more information there is no way to tell you what exactly is the problem...

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

            Q 1 Reply Last reply
            3
            • jsulmJ jsulm

              @Qt-embedded-developer The correct question is: where do I have to use a mutex? If QMutex freezes your app that means that you have a dead lock. But without more information there is no way to tell you what exactly is the problem...

              Q Offline
              Q Offline
              Qt embedded developer
              wrote on last edited by
              #5

              @jsulm

              i have written one function which get accessed in thread at every 500 ms and same function i have accessed outside this thread . so some time dead lock situation get created. now to avoid that situation i want to use QMutex.

              But i does not have much knowledge regarding where i need to use Qmutex lock and unlock .

              I have seen that mutex lock and unlock some times freeze application.

              So i need description in which scenario of Qmutex lock and unlock function freeze application?

              jsulmJ JonBJ 2 Replies Last reply
              0
              • Q Qt embedded developer

                @jsulm

                i have written one function which get accessed in thread at every 500 ms and same function i have accessed outside this thread . so some time dead lock situation get created. now to avoid that situation i want to use QMutex.

                But i does not have much knowledge regarding where i need to use Qmutex lock and unlock .

                I have seen that mutex lock and unlock some times freeze application.

                So i need description in which scenario of Qmutex lock and unlock function freeze application?

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

                @Qt-embedded-developer said in when QMutex block my program ? when this thing will happen ?:

                so some time dead lock situation get created

                You mean "race condition". "Dead locks" occur when you use mutexes.

                "So i need description in which scenario of Qmutex lock and unlock function freeze application?" - you need to protect critical parts in your code from being accessed at the same time from different threads. This was already answered in your other thread.

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

                1 Reply Last reply
                1
                • Q Qt embedded developer

                  @jsulm

                  i have written one function which get accessed in thread at every 500 ms and same function i have accessed outside this thread . so some time dead lock situation get created. now to avoid that situation i want to use QMutex.

                  But i does not have much knowledge regarding where i need to use Qmutex lock and unlock .

                  I have seen that mutex lock and unlock some times freeze application.

                  So i need description in which scenario of Qmutex lock and unlock function freeze application?

                  JonBJ Online
                  JonBJ Online
                  JonB
                  wrote on last edited by
                  #7

                  @Qt-embedded-developer
                  There is not much to explain. If two threads both execute a QMutex lock on the same resource, then the second arrival one will sleep/block until the first arrival releases the lock. So if the non-UI thread is holding a lock and has not released it, the main UI thread will block --- and be unresponsive --- until the secondary thread releases it.

                  It therefore behoves you to ensure you lock the minimum amount of code which is safe, and have a thread which holds a lock complete whatever it needs to do as fast as possible.

                  There is no "magic workaround" for this. If the two threads in question genuinely each need to hold a lock then that is how it is, the second one cannot proceed safely until the first one is done.

                  1 Reply Last reply
                  2

                  • Login

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