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. How to not interrupt back ground thread and also allow foreground ui function to get executed ?
Forum Updated to NodeBB v4.3 + New Features

How to not interrupt back ground thread and also allow foreground ui function to get executed ?

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 6 Posters 1.5k Views 3 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #8

    Hi,

    The question is: why do you want these interruptions in the first place ? What is the rational for that idea ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    Q 1 Reply Last reply
    0
    • SGaistS SGaist

      Hi,

      The question is: why do you want these interruptions in the first place ? What is the rational for that idea ?

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

      @SGaist Because i have to allow ticket creation at highest priority while background data sending to server need to be done at lowest priority.

      For example in bus ticket created by conductor. we can not stop conductor to create ticket. we can only interrupt the background thread to send that data to server.

      So interruption needed at first place.

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #10

        But that's the main idea of threads: there is no need to interrupt anything! Your foreground and background threads can run in parallel, both doing their job at the same time.

        (Z(:^

        Q 1 Reply Last reply
        2
        • sierdzioS sierdzio

          But that's the main idea of threads: there is no need to interrupt anything! Your foreground and background threads can run in parallel, both doing their job at the same time.

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

          @sierdzio Hi !!

          But there is one situation make my sqlite database get locked .

          Because my back ground thread and foreground function use mutex lock that make my sqlite db to get locked . and i want to stop locking of database.

          So How to deal with this situation ?

          jsulmJ 1 Reply Last reply
          0
          • Q Qt embedded developer

            @sierdzio Hi !!

            But there is one situation make my sqlite database get locked .

            Because my back ground thread and foreground function use mutex lock that make my sqlite db to get locked . and i want to stop locking of database.

            So How to deal with this situation ?

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

            @Qt-embedded-developer said in How to not interrupt back ground thread and also allow foreground ui function to get executed ?:

            So How to deal with this situation ?

            You expect to get clear answer without showing your code? Especially how you lock.
            Here some hints: https://en.wikipedia.org/wiki/Deadlock#Prevention

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

            Q 1 Reply Last reply
            1
            • jsulmJ jsulm

              @Qt-embedded-developer said in How to not interrupt back ground thread and also allow foreground ui function to get executed ?:

              So How to deal with this situation ?

              You expect to get clear answer without showing your code? Especially how you lock.
              Here some hints: https://en.wikipedia.org/wiki/Deadlock#Prevention

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

              @jsulm In my case deadlock situation happen due to mutual exclusion because the foreground and background hold one resource sqlite database.

              And so database get locked .

              I want to avoid this situation.

              JonBJ 1 Reply Last reply
              0
              • Q Qt embedded developer

                @jsulm In my case deadlock situation happen due to mutual exclusion because the foreground and background hold one resource sqlite database.

                And so database get locked .

                I want to avoid this situation.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #14

                @Qt-embedded-developer said in How to not interrupt back ground thread and also allow foreground ui function to get executed ?:

                one resource sqlite database

                Before commenting on what you have said, could you clarify: do you mean a SQLite database file which is supplied and opened as a Qt resource file, or do you mean "resource" in a broad sense and you are just talking about an external SQLite file, not a Qt resource?

                Q 1 Reply Last reply
                0
                • sierdzioS Offline
                  sierdzioS Offline
                  sierdzio
                  Moderators
                  wrote on last edited by
                  #15

                  Sounds like the solution would be to keep the SQLite DB opened by only one thread, which should in turn distribute the data as necessary to other parts of the application, for example using signals and slots. No locking and no mutexes :-)

                  BTW. be very careful with SQLite and threads, by default it does not support them. You need to compile SQLite yourself. See https://sqlite.org/threadsafe.html

                  (Z(:^

                  Q S 2 Replies Last reply
                  3
                  • JonBJ JonB

                    @Qt-embedded-developer said in How to not interrupt back ground thread and also allow foreground ui function to get executed ?:

                    one resource sqlite database

                    Before commenting on what you have said, could you clarify: do you mean a SQLite database file which is supplied and opened as a Qt resource file, or do you mean "resource" in a broad sense and you are just talking about an external SQLite file, not a Qt resource?

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

                    @JonB
                    I mean "resource" in a broad sense and i am talking about an external SQLite file, not a qt resource

                    1 Reply Last reply
                    0
                    • sierdzioS sierdzio

                      Sounds like the solution would be to keep the SQLite DB opened by only one thread, which should in turn distribute the data as necessary to other parts of the application, for example using signals and slots. No locking and no mutexes :-)

                      BTW. be very careful with SQLite and threads, by default it does not support them. You need to compile SQLite yourself. See https://sqlite.org/threadsafe.html

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

                      @sierdzio Thanks for Help ..

                      1 Reply Last reply
                      0
                      • sierdzioS sierdzio

                        Sounds like the solution would be to keep the SQLite DB opened by only one thread, which should in turn distribute the data as necessary to other parts of the application, for example using signals and slots. No locking and no mutexes :-)

                        BTW. be very careful with SQLite and threads, by default it does not support them. You need to compile SQLite yourself. See https://sqlite.org/threadsafe.html

                        S Offline
                        S Offline
                        SimonSchroeder
                        wrote on last edited by
                        #18

                        @sierdzio said in How to not interrupt back ground thread and also allow foreground ui function to get executed ?:

                        BTW. be very careful with SQLite and threads, by default it does not support them. You need to compile SQLite yourself. See https://sqlite.org/threadsafe.html

                        The link you provided states that by default SQLite uses serialized access, i.e. it is thread safe by default.

                        @Qt-embedded-developer You should not use mutexes to access SQLite. With the proper settings multiple connections to the same SQLite file can be open. SQLite will do all the synchronization. You might get into trouble if one of the threads reads quite often and the other thus cannot lock it for writing.

                        Maybe you can clarify what you are actually trying to do. You should not use a database to communicate between two threads (one polling if there is something new to be sent over the network). My guess is that you don't need mutexes at all. In order for the GUI thread to communicate that there is something new to be sent, just use signals and slots between the two threads to communicate. All requests from the GUI will be queued inside the event loop of the network thread and handled one after the other. This is how Qt should be used.

                        1 Reply Last reply
                        3

                        • Login

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