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. What should be best mechanism to stop and start same thread again?
Forum Updated to NodeBB v4.3 + New Features

What should be best mechanism to stop and start same thread again?

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 4 Posters 706 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.
  • Q Offline
    Q Offline
    Qt embedded developer
    wrote on last edited by
    #1

    I have created one class

    Which shared between both

    This class have one queue

    Using this class I have created 2 queue

    In one of that queue frontend will write data using safeguard lock and it will be read by backend

    In other queue back end will write data and front will read data

    Now to not block GUI I have created 2 thread on front end side where one will do write and other do reading

    What should be best mechanism to stop and start same thread again so that when data is not available at that time we can save usage of cpu?

    In this queue

    I want to push the one command

    Which have

    Struct {
    Int id;
    String type;
    // here I am confused what I should declare so that there any number of data I can pass
    }

    So what I should declare 3rd var?

    Pl45m4P 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Isn't QWaitCondition what you are looking for ?
      Check the associated producer consumer example.

      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
      2
      • SGaistS SGaist

        Hi,

        Isn't QWaitCondition what you are looking for ?
        Check the associated producer consumer example.

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

        @SGaist what about
        My third variable to declare? Where I mentioned below comment
        // here I am confused what I should declare so that there any number of data I can pass

        I want to share here information it can be any type of information

        SGaistS 1 Reply Last reply
        0
        • Q Qt embedded developer

          @SGaist what about
          My third variable to declare? Where I mentioned below comment
          // here I am confused what I should declare so that there any number of data I can pass

          I want to share here information it can be any type of information

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Qt-embedded-developer "any number of data" ? What is the type of data ? Once you know that, you can use a QList<TypeOfData>.

          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
          • Q Qt embedded developer

            I have created one class

            Which shared between both

            This class have one queue

            Using this class I have created 2 queue

            In one of that queue frontend will write data using safeguard lock and it will be read by backend

            In other queue back end will write data and front will read data

            Now to not block GUI I have created 2 thread on front end side where one will do write and other do reading

            What should be best mechanism to stop and start same thread again so that when data is not available at that time we can save usage of cpu?

            In this queue

            I want to push the one command

            Which have

            Struct {
            Int id;
            String type;
            // here I am confused what I should declare so that there any number of data I can pass
            }

            So what I should declare 3rd var?

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by Pl45m4
            #5

            @Qt-embedded-developer said in What should be best mechanism to stop and start same thread again?:

            So what I should declare 3rd var?

            This says it all... Since it's C++ (and not something like JS, where you can have "variable Varibales") , you need to know what datatype you put there before you compile/run it.
            In general one could use <T> templates or void pointers to your "data" but in your case , in a struct it might be difficult.
            So there is no way that you know before what kind of data is stored there?! Why you not know? Re-think your design. Or create different structs for different cases


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            1 Reply Last reply
            0
            • SGaistS SGaist

              @Qt-embedded-developer "any number of data" ? What is the type of data ? Once you know that, you can use a QList<TypeOfData>.

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

              @SGaist @Pl45m4 i know that using json format we can send as many as various types of data. So similar way I want to create structure that replace json format

              JonBJ SGaistS 3 Replies Last reply
              0
              • Q Qt embedded developer

                @SGaist @Pl45m4 i know that using json format we can send as many as various types of data. So similar way I want to create structure that replace json format

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

                @Qt-embedded-developer
                One Qt type which approximates JSON's variety of types is QVariant/QVariantList etc. I don't know what your case is where you do not define the type/structure of your data. QList<TypeOfData> might be preferable, but QVariant allows for a number of underlying types in answer to your question.

                1 Reply Last reply
                0
                • Q Qt embedded developer

                  @SGaist @Pl45m4 i know that using json format we can send as many as various types of data. So similar way I want to create structure that replace json format

                  SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Qt-embedded-developer JSON is a textual exchange format which C++ is not. You can't create new data structure out of the blue without any prior knowledge like that.

                  What exactly are you trying to put in that structure ?

                  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
                  1
                  • SGaistS SGaist

                    @Qt-embedded-developer JSON is a textual exchange format which C++ is not. You can't create new data structure out of the blue without any prior knowledge like that.

                    What exactly are you trying to put in that structure ?

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

                    @SGaist @JonB

                    My actually requirement is like

                    Consider in ui there are several button for different devices

                    Now when any button get clicked I need to send request through this type of data structure so when response is send by backend

                    Based on devices properties there could be more or less data in various format comes.

                    And this type of data I need put to send and receive

                    1 Reply Last reply
                    0
                    • Q Qt embedded developer

                      @SGaist @Pl45m4 i know that using json format we can send as many as various types of data. So similar way I want to create structure that replace json format

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

                      @Qt-embedded-developer said in What should be best mechanism to stop and start same thread again?:

                      i know that using json format we can send as many as various types of data. So similar way I want to create structure that replace json format

                      So going back to this. If you really do want to pass a bunch of unknown, arbitrary data structures around JSON is a possibility. Why do you want to "replace" JSON format?

                      Q 1 Reply Last reply
                      1
                      • JonBJ JonB

                        @Qt-embedded-developer said in What should be best mechanism to stop and start same thread again?:

                        i know that using json format we can send as many as various types of data. So similar way I want to create structure that replace json format

                        So going back to this. If you really do want to pass a bunch of unknown, arbitrary data structures around JSON is a possibility. Why do you want to "replace" JSON format?

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

                        @JonB because there is clear requirement that we should not use json, we need to find alternative like using C++17 and any custom data structure

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

                          @JonB because there is clear requirement that we should not use json, we need to find alternative like using C++17 and any custom data structure

                          SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @Qt-embedded-developer what is the justification of that requirement ?

                          You can make use of Qt's JSON classes to parse and generate from / to the backend.

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

                          1 Reply Last reply
                          0
                          • Q Qt embedded developer

                            @JonB because there is clear requirement that we should not use json, we need to find alternative like using C++17 and any custom data structure

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

                            @Qt-embedded-developer
                            If that is your requirement then you can always restrict yourself to the same subset of types as JSON does. From Qt use QList<> for lists/arrays (JSON [...]) and QMap<> for objects with keys (JSON {...}). Or equivalent std:: types if that floats your boat.

                            1 Reply Last reply
                            3
                            • Q Qt embedded developer has marked this topic as solved on
                            • JonBJ JonB referenced this topic on

                            • Login

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