小编che*_*lin的帖子

多线程不起作用(不比单线程快)

我正在尝试使用一个简单的求和任务来测试多线程,我想在其中比较单线程与多线程。

单线程:

long long summation(int start, int end)
{
    long long total = 0; 
    for (int i = start; i < end; i++)
    {
        total += i;
    }
    return total;
}
Run Code Online (Sandbox Code Playgroud)

和多线程:

long long threadedSummation(int numThreads, int start, int end)
{
    long long total = 0;
    int summationRange = (start + end) / numThreads; //The range of numbers for every thread to calculate
    for (int i = 0; i < numThreads; i++)
    {
        int start = summationRange * i;
        int …
Run Code Online (Sandbox Code Playgroud)

c++ multithreading asynchronous future

0
推荐指数
1
解决办法
72
查看次数

标签 统计

asynchronous ×1

c++ ×1

future ×1

multithreading ×1