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. Wait until condition is not met - but why mutex?

Wait until condition is not met - but why mutex?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qwaitcondition
14 Posts 3 Posters 1.5k 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.
  • T Offline
    T Offline
    TomNow99
    wrote on 16 Jun 2020, 19:04 last edited by
    #5

    @SGaist I can't find function like wait() when I want to use signals and slots. Of course in slot I can set variable a.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 16 Jun 2020, 19:05 last edited by
      #6

      Because there are none.

      Can you explain what your two threads are doing ? Especially why the first one needs to wait for a to be equal to 6 ?

      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
      • T Offline
        T Offline
        TomNow99
        wrote on 16 Jun 2020, 19:12 last edited by
        #7

        @SGaist I don't have at the moment very good example Sometimes I have code:

        fun()
        {
        fun1();
        fun2();
        fun3();
        }
        
        void timerTimeoutSlot()
        {
        do Something // for example set very important Variable;
        }
        

        I would like to something like:

        fun()
        {
        fun1();
        wait when the very important variable will be set
        fun2();
        fun3();
        }
        

        Because when this variable will not set my fun2() can't be execute.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 16 Jun 2020, 19:15 last edited by
          #8

          And fun should be called repeatedly ?

          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
          • T Offline
            T Offline
            TomNow99
            wrote on 16 Jun 2020, 19:24 last edited by TomNow99
            #9

            @SGaist said in Wait until condition is not met - but why mutex?:

            repeatedly

            When I look at my code I think I can do something like:

            void timerTimeoutSlot()
            {
            do Something // for example set very important Variable;
            fun2();
            fun3();
            }
            

            But Could you tell me what is going on when signal is emitted? I talk about only 1 thread. For example:

            function()
            {
            operation a;
            operation b;
            operation c;
            operation d;
            operation e;
            operation f;
            }
            
            timerTimeoutSlot()
            {
            operation m;
            operation n;
            operation o;
            }
            
            timer2TimeoutSlot()
            {
            operation x;
            operation y;
            operation z;
            }
            

            And when the operation c is execute, signal timeout in timer1 is emitted
            So operations will be execute like:
            a -> b -> c -> m -> n -> o -> d -> e -> f?

            And second question:
            When the operation c is execute, signal timeout in timer1 is emitted and when operation m is execute, signal timeout in timer 2 is emitted. So operation will be execute like:
            a -> b -> c -> m -> x->y->z->n -> o -> d -> e -> f?

            EDIT:
            I hear that can be something like:
            a -> b -> c -> m -> d->n->e->o->f ( in first question )

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 16 Jun 2020, 19:27 last edited by
              #10

              If single threaded, the slots will be called after the functions are done in order.

              Looks like you are trying to model some sort of behaviour. What would that be ?

              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 16 Jun 2020, 19:34
              1
              • S SGaist
                16 Jun 2020, 19:27

                If single threaded, the slots will be called after the functions are done in order.

                Looks like you are trying to model some sort of behaviour. What would that be ?

                Q Offline
                Q Offline
                qwe3
                wrote on 16 Jun 2020, 19:34 last edited by
                #11

                @SGaist so will be a b c d e f m n o
                Or
                A b c m d n e o f?

                I am a newbie programmer, so my questions are not very smart and I dont have any plans.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 16 Jun 2020, 19:39 last edited by
                  #12

                  Your answers makes it look like you are trying to model some behaviour that could be represented by a state machine rather that complex threading.

                  Since you are starting in the programming field, you should rather stay away from the threading paradigm and learn the rest first. Threading is a very complex topic that offers you many way to shoot yourself in the foot from different unrelated angles at different unrelated time with different unrelated side-effects that will want to go after your foot again.

                  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 16 Jun 2020, 19:56
                  2
                  • S SGaist
                    16 Jun 2020, 19:39

                    Your answers makes it look like you are trying to model some behaviour that could be represented by a state machine rather that complex threading.

                    Since you are starting in the programming field, you should rather stay away from the threading paradigm and learn the rest first. Threading is a very complex topic that offers you many way to shoot yourself in the foot from different unrelated angles at different unrelated time with different unrelated side-effects that will want to go after your foot again.

                    Q Offline
                    Q Offline
                    qwe3
                    wrote on 16 Jun 2020, 19:56 last edited by
                    #13

                    @SGaist Ok :) I will learn thread after easier thing. But please answer for my question about operations. Thank you

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 18 Jun 2020, 18:30 last edited by
                      #14

                      If timer2 timeout value is greater than timer they will be in order: function -> timerTimeoutSlot -> timer2TimeoutSlot.

                      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

                      14/14

                      18 Jun 2020, 18:30

                      • Login

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