Reusing thread in loop c++

前端 未结 6 1052
余生分开走
余生分开走 2020-11-29 02:45

I need to parallelize some tasks in a C++ program and am completely new to parallel programming. I\'ve made some progress through internet searches so far, but am a bit stu

6条回答
  •  误落风尘
    2020-11-29 03:22

    You also could make your own Thread class and call its run method like:

    class MyThread
    {
    public:
    void run(std::function func) {
       thread_ = std::thread(func);
    }
    void join() {
       if(thread_.joinable())
          thread_.join();
    }
    private:
       std::thread thread_;
    };
    
    // Application code...
    MyThread myThread;
    myThread.run(AcquireData);
    

提交回复
热议问题