Multithread program in C++ shows the same performance as a serial one

后端 未结 3 1864
一生所求
一生所求 2020-12-19 14:16

I just want to write a simple program in C++, which creates two threads and each of them fills vector by squares of integers (0, 1, 4, 9, ...). Here is my code:



        
3条回答
  •  借酒劲吻你
    2020-12-19 15:09

    The fill function will run so fast that the thread overhead is likely as long as the execuition.

    Replace fill with something that takes a significant amount of time to execute. As a first pass, use std::this_thread::sleep_for

提交回复
热议问题