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

后端 未结 4 1309
-上瘾入骨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

    This is guarantee that every thread will be created in vector's storage. No object byte will be copied.

    for (int &reader : readers)
        readerThreads.emplace_back( readerThread::start, reader );
    

    In common case this not the same as @Seth suggested. But in current case it is 99% the same.

提交回复
热议问题