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. What is way to give highest priority to normal function over mutex based single thread in main program?
Forum Updated to NodeBB v4.3 + New Features

What is way to give highest priority to normal function over mutex based single thread in main program?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
9 Posts 3 Posters 949 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
    #1
    This post is deleted!
    jsulmJ 1 Reply Last reply
    0
    • Q Qt embedded developer

      This post is deleted!

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

      @Qt-embedded-developer said in What is way to give highest priority to normal function over mutex based single thread in main program?:

      So Guide me How to give highest priority to Ticket creation function over mutex based single thread in main program ?

      Mutex in single thread application?! Why?
      Why do you need threads at all?

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

      Q 2 Replies Last reply
      1
      • jsulmJ jsulm

        @Qt-embedded-developer said in What is way to give highest priority to normal function over mutex based single thread in main program?:

        So Guide me How to give highest priority to Ticket creation function over mutex based single thread in main program ?

        Mutex in single thread application?! Why?
        Why do you need threads at all?

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

        @jsulm

        I used Mutex in single thread is set for send data to server in background without fail . as well as when in foreground any ticket creation call happen at that time i want to add that ticket number also.

        So i have to give highest priority to ticket creation in foreground and at same time i does not want to miss any sending transaction details in background.

        Can you help me which theoretical concept will help me to solve this problem?

        Thanks for help.

        JonBJ 1 Reply Last reply
        0
        • Q Qt embedded developer

          @jsulm

          I used Mutex in single thread is set for send data to server in background without fail . as well as when in foreground any ticket creation call happen at that time i want to add that ticket number also.

          So i have to give highest priority to ticket creation in foreground and at same time i does not want to miss any sending transaction details in background.

          Can you help me which theoretical concept will help me to solve this problem?

          Thanks for help.

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

          @Qt-embedded-developer
          I cannot see why you would want mutexs in a single-threaded application. I don't understand what you are saying (and probably won't even if you clarify!).

          You can (try to) set thread priority via QThread::setPriority(). Though as it says there if you are using e.g. Linux it will have no effect.

          One would suspect that, like many users, you are over-engineering by trying to delve into threads here. If you are performing an operation once every five minutes it's hard to see why thread priority would be an issue, and relying on thread priority to achieve/alter any behaviour is dubious.

          Q 1 Reply Last reply
          1
          • JonBJ JonB

            @Qt-embedded-developer
            I cannot see why you would want mutexs in a single-threaded application. I don't understand what you are saying (and probably won't even if you clarify!).

            You can (try to) set thread priority via QThread::setPriority(). Though as it says there if you are using e.g. Linux it will have no effect.

            One would suspect that, like many users, you are over-engineering by trying to delve into threads here. If you are performing an operation once every five minutes it's hard to see why thread priority would be an issue, and relying on thread priority to achieve/alter any behaviour is dubious.

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

            @JonB @jsulm Hi !

            it's my requirement that i have to allow create ticket functionality in foreground and at same time if Background thread is running state after 5 minute i have to give highest priority to ticket creation function.

            So how to synchronize this program this code i need suggestion what i need to do?

            for example conductor create ticket for passenger and at same time already generated ticket numbers i need to send to server at every 20 minute when bus is in running state.

            1 Reply Last reply
            0
            • jsulmJ jsulm

              @Qt-embedded-developer said in What is way to give highest priority to normal function over mutex based single thread in main program?:

              So Guide me How to give highest priority to Ticket creation function over mutex based single thread in main program ?

              Mutex in single thread application?! Why?
              Why do you need threads at all?

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

              @jsulm Because i have created one loop using goto statement for ticket creation and created one thread to send that data to server from background every 20 minute.

              jsulmJ 1 Reply Last reply
              0
              • Q Qt embedded developer

                @jsulm Because i have created one loop using goto statement for ticket creation and created one thread to send that data to server from background every 20 minute.

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

                @Qt-embedded-developer said in What is way to give highest priority to normal function over mutex based single thread in main program?:

                using goto statement

                What? goto?! Why on earth goto?!
                Sorry, I really don't understand your description and don't see why you need threads. Maybe somebody else understands your descriptions better...

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

                Q 1 Reply Last reply
                1
                • jsulmJ jsulm

                  @Qt-embedded-developer said in What is way to give highest priority to normal function over mutex based single thread in main program?:

                  using goto statement

                  What? goto?! Why on earth goto?!
                  Sorry, I really don't understand your description and don't see why you need threads. Maybe somebody else understands your descriptions better...

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

                  @jsulm @JonB

                  My code is written like below :

                  void function ()
                  {
                  check key pressed :
                  
                  if(IsEnterKeypressed())
                  createticketnumber();
                  else
                  goto  check key pressed;
                  
                  }
                  
                  int main()
                    {
                  
                    // create thread using pthread_create which store ticket related details //from ticket db to config db. and send ticket related details to server db //a every 20 minute 
                    }
                    
                    void thread_fun ()
                    {
                  
                    // here i ask conductor that he want to generate ticket 
                  function ();
                  
                    //pythread_mutex_lock();
                    //logic of store ticket related details from ticket db to config db. and send ticket related details to server db
                    //pythread_mutex_unlock();
                    }
                  

                  I hope now you will understand the why i have used goto statement.

                  JonBJ 1 Reply Last reply
                  0
                  • Q Qt embedded developer

                    @jsulm @JonB

                    My code is written like below :

                    void function ()
                    {
                    check key pressed :
                    
                    if(IsEnterKeypressed())
                    createticketnumber();
                    else
                    goto  check key pressed;
                    
                    }
                    
                    int main()
                      {
                    
                      // create thread using pthread_create which store ticket related details //from ticket db to config db. and send ticket related details to server db //a every 20 minute 
                      }
                      
                      void thread_fun ()
                      {
                    
                      // here i ask conductor that he want to generate ticket 
                    function ();
                    
                      //pythread_mutex_lock();
                      //logic of store ticket related details from ticket db to config db. and send ticket related details to server db
                      //pythread_mutex_unlock();
                      }
                    

                    I hope now you will understand the why i have used goto statement.

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

                    @Qt-embedded-developer said in What is way to give highest priority to normal function over mutex based single thread in main program?:

                    I hope now you will understand the why i have used goto statement.

                    I do not know why you have chosen to use a goto statement here! :) Even if you want this code it can be written as:

                    while (true)
                    {
                        if (IsEnterKeypressed())
                        {
                            createticketnumber();
                            break;
                        }
                    }
                    

                    Which I think is more readable/makes behaviour clearer. However, this (or your code) is an awful way to write it :( Your code runs continuously, at least until a key is pressed. Even though it is a thread, this means that thread will be using loads of CPU time. It is true that it will still allow your main UI thread to run, because it is a thread, but your computer will be permanently busy running the while/goto loop.

                    Furthermore: I don't know how your IsEnterKeypressed() is implemented. But assuming this interacts with the keyboard then, although I am not certain about this in Qt, I would have thought that counts as a "UI" operation and should only be done in the main UI thread, not a processing thread, as normally required in Qt.

                    I'm sorry to say this, but every beginner-ish person here seems to think they need & understand threads, when they do not. I do not know how your system works or is intended to work, but would suggest this is not the way to do it.

                    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