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. Please help to synchronize the execution of processes
Forum Update on Monday, May 27th 2025

Please help to synchronize the execution of processes

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 3 Posters 2.3k 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.
  • S Offline
    S Offline
    smartcoder.v.arch
    wrote on last edited by
    #1

    Hi again, dear community. Please, help me to solve the following question or give a reference to the information or better - to custom example. I have such a problem. There are two processes. The first process sends (emit) a signal with the parameter QImage* p_img to the second class , which saves the image *p_img to the disk and removes p_img. Of course the second process performs its task more slowly than the first one and data is accumulated in RAM as the calls of unprocessed signals are in the queue. Here is the question -how is it possible with Qt libraries to implement the living queue for 3 processes. Example - implementation of select{..} in Golang

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      @smartcoder.v.arch said in Please help to synchronize the execution of processes:

      implementation of select{..} in Golang

      the closest thin is QtConcurrent, something like http://doc.qt.io/qt-5/qtconcurrent.html#run

      The rest of the question is quite confusing as you are mixing processes an threads. if you make what you are trying to do more clear we might be more helpful

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      S 2 Replies Last reply
      1
      • VRoninV VRonin

        @smartcoder.v.arch said in Please help to synchronize the execution of processes:

        implementation of select{..} in Golang

        the closest thin is QtConcurrent, something like http://doc.qt.io/qt-5/qtconcurrent.html#run

        The rest of the question is quite confusing as you are mixing processes an threads. if you make what you are trying to do more clear we might be more helpful

        S Offline
        S Offline
        smartcoder.v.arch
        wrote on last edited by
        #3

        @VRonin Thanks for Your answer. I'll try to explain. My program is designed to convert video into gif. The code will be opened, but it is not about that right now. I use "QAbstractVideoSurface" class and in its method "QAbstractVideoSurface::present" with the help of a signal I transmit "void frameAvailable (QImage p_img)" pass a pointer of the image to another class, the task of which is to perform the change of the size of the image, that p_img pointer points to and saving of it to the hard drive and then release the memory that allocated to p_img. The problem is that the size of the operation of the saving and the changing of the size performs for too long and the calls "void frameAvailable(QImage p_img)" wait for the processing and take quite much of the RAM. I would like to make 3 or more processes gain data from "void frameAvailable(QImage* p_img)", and as soon as one of these processes will complete its operation, it accepts the new task, that is, to organize a sort of instruction pipeline, where one process conveys the instructions to 5 processes-workers and they perform it simultaneously.

        1 Reply Last reply
        0
        • VRoninV VRonin

          @smartcoder.v.arch said in Please help to synchronize the execution of processes:

          implementation of select{..} in Golang

          the closest thin is QtConcurrent, something like http://doc.qt.io/qt-5/qtconcurrent.html#run

          The rest of the question is quite confusing as you are mixing processes an threads. if you make what you are trying to do more clear we might be more helpful

          S Offline
          S Offline
          smartcoder.v.arch
          wrote on last edited by
          #4

          @VRonin Sorry , I WAS WRONG - the stream (not a process)

          1 Reply Last reply
          0
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5
            // declare this global function
            void saveImage(QImage* p_img){
            // do your stuff here
            // p_img->scaled().save();
            delete p_img;
            }
            // connect(videosurface,&MyVideoSurface::frameAvailable,someclass,&SomeClass::saveFrame);
            void SomeClass::saveFrame(QImage* p_img){
            QtConcurrent::run(saveImage,p_img);
            }
            

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            S 2 Replies Last reply
            2
            • VRoninV VRonin
              // declare this global function
              void saveImage(QImage* p_img){
              // do your stuff here
              // p_img->scaled().save();
              delete p_img;
              }
              // connect(videosurface,&MyVideoSurface::frameAvailable,someclass,&SomeClass::saveFrame);
              void SomeClass::saveFrame(QImage* p_img){
              QtConcurrent::run(saveImage,p_img);
              }
              
              S Offline
              S Offline
              smartcoder.v.arch
              wrote on last edited by
              #6

              @VRonin Thank you. I'll try your solution and will write you tomorrow here

              1 Reply Last reply
              0
              • VRoninV VRonin
                // declare this global function
                void saveImage(QImage* p_img){
                // do your stuff here
                // p_img->scaled().save();
                delete p_img;
                }
                // connect(videosurface,&MyVideoSurface::frameAvailable,someclass,&SomeClass::saveFrame);
                void SomeClass::saveFrame(QImage* p_img){
                QtConcurrent::run(saveImage,p_img);
                }
                
                S Offline
                S Offline
                smartcoder.v.arch
                wrote on last edited by
                #7

                @VRonin One more question - how safe is your method? As I understand the function will be called in a new stream each time?.. How many streams the same time is acceptably? What will happen if the number of calls of function will achieve 1000?

                mrjjM 1 Reply Last reply
                0
                • S smartcoder.v.arch

                  @VRonin One more question - how safe is your method? As I understand the function will be called in a new stream each time?.. How many streams the same time is acceptably? What will happen if the number of calls of function will achieve 1000?

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @smartcoder.v.arch
                  Hi
                  It most likely depends on the hardware if it can handle 1000 concurrent saveImage.
                  Also, the bottleneck could be the IO system, if they are accessing the drive to store at the same time.
                  Furthermore, some platforms might have limited amount of open file handles
                  possible and many other factors like that.

                  You can control how many is allowed with
                  QThreadPool::globalInstance()->setMaxThreadCount(n)
                  http://doc.qt.io/qt-5/qthreadpool.html#maxThreadCount-prop
                  ( as far as i know)

                  1 Reply Last reply
                  0
                  • VRoninV Offline
                    VRoninV Offline
                    VRonin
                    wrote on last edited by VRonin
                    #9

                    QtConcurrent is multi-threading made easy. it has some limitations (that can be overcame with QThread) but it is also safer than a naive call to std::async

                    from http://doc.qt.io/qt-5/qtconcurrent-index.html

                    QtConcurrent automatically adjust the number of threads used according to the number of processor cores available.

                    What will happen if the number of calls of function will achieve 1000?

                    it will execute QThread::idealThreadCount() saves at the same time and queue the others as stated here: http://doc.qt.io/qt-5/qtconcurrent.html#run

                    Note that function may not run immediately; function will only be run once a thread becomes available.

                    P.S.
                    what you call stream is called thread

                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                    ~Napoleon Bonaparte

                    On a crusade to banish setIndexWidget() from the holy land of Qt

                    1 Reply Last reply
                    2
                    • S Offline
                      S Offline
                      smartcoder.v.arch
                      wrote on last edited by
                      #10

                      Thank Friends for Your answers . And sorry for my English.

                      1 Reply Last reply
                      1

                      • Login

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