How to create an array of thread objects in C++11?

前端 未结 2 470
[愿得一人]
[愿得一人] 2021-02-01 16:21

I want to learn how to create multiple threads with the new C++ standard library and store their handles into an array.
How can I start a thread?
The examples that I saw

2条回答
  •  天命终不由人
    2021-02-01 16:37

    Nothing fancy required; just use assignment. Inside your loop, write

    myThreads[i] = std::thread(exec, i);
    

    and it should work.

提交回复
热议问题