C++ std::vector of independent std::threads

后端 未结 4 1313
-上瘾入骨i
-上瘾入骨i 2021-01-11 10:11

I´m building a real time software where I have a main infinite loops on main() and threads used to read and process data.

One of the issues is keeping a

4条回答
  •  广开言路
    2021-01-11 10:49

    Another variant that works is to create your thread object in the vector.push_back call. No need to call std::move in this case because its already an rvalue (thus it will be be moved).

    for (int &reader : readers)
        readerThreads.push_back(std::thread(readerThread::start, reader));
    

提交回复
热议问题