The problem with the implementation of the pipeline

I created an application that uses a pipeline template to do some processing. However, I noticed that when the pipeline starts several times in a row, it becomes slower and slower.

This is also the case when the actual processing is not performed at the pipeline stages - so I'm curious, maybe the problem with my pipeline has problems.

This is a simple test program that redefines the effect:

#include <iostream>
#include <boost/thread.hpp>

class Pipeline {

    void processStage(int i) {

        return;
    }


public:

    void run() {


        boost::thread_group threads;

        for (int i=0; i< 8; ++i) {

            threads.add_thread(new boost::thread(&Pipeline::processStage, this, i));
        }

        threads.join_all();
    }
};



int main() {


    Pipeline pipeline;

    int n=2000;
    for (int i=0;i<n; ++i) {

            pipeline.run();

            if (((i+1)*100)/n > (i*100)/n) 
                std::cout << "\r" << ((i+1)*100)/n << " %";
    }

}

In my understanding, threads are created in run () and at the end of run () they end. Thus, the state of the program at the beginning of the external cycle in the main program should always be the same ...

But I am seeing a gradual slowdown in processing this cycle.

, , , .

! Constantin

+5
2

run(), (500 ) main(), () . , , , " ", .

+1

boost:: thread(), ? Windows, . , , , , . , , , .

0

All Articles