[图像Debug工具]多线程任务分发

c 复制代码
#include <iostream>

using namespace std;

uint8_t *st_point[4];
uint8_t *ed_point[4];
#define THREAD_NUMS 10

void calc_thread_range(uint8_t *buf, uint64_t length, uint8_t *st_point[THREAD_NUMS], uint8_t *ed_point[THREAD_NUMS])
{
    int i = 0;
    int cur_pos = 0;
    int pos_record[THREAD_NUMS + 2] = {0};

    pos_record[0] = 0;

    for(i = 0; i < THREAD_NUMS; i++)
    {
        cur_pos = length / THREAD_NUMS * (i + 1);
        while(buf[cur_pos] != '\n')
        {
            cur_pos--;
        }
        pos_record[i + 1] = cur_pos;
    }

    pos_record[THREAD_NUMS + 1] = length;

}

int main()
{
    char buf[1024] = {0};
    clock_t start = 0, finish = 0;
    start = clock();
    int i = 0;
    FILE *f = fopen("test.txt", "rb");
    fseek(f, 0, SEEK_END);
    long size = ftell(f);
    fseek(f, 0, SEEK_SET);
    uint8_t *buf_heap = new uint8_t[size];
    fread(buf_heap, 1, size, f);
    calc_thread_range(buf_heap, size, st_point, ed_point);
//    while (!feof(f)) {
//        i++;
//        fscanf(f, "%s", buf);
//    }
    fclose(f);

    finish = clock();

    cout << i << endl;
    cout << finish - start << endl;

    cout << "Hello World!" << endl;
    return 0;
}
相关推荐
郝学胜_神的一滴2 小时前
CMake 30:循环语法全解|foreach_while双循环精讲、迭代技巧与实战避坑指南
c++·cmake
To_OC13 小时前
LC 128 最长连续序列:别上来就排序,O (n) 解法才是这题的灵魂
javascript·算法·leetcode
05Kevin1 天前
lk每日冒险题--数据结构6.27
算法
To_OC2 天前
从一次栈溢出报错说起,我把递归彻底扒明白了
javascript·算法·程序员
千纸鹤安安2 天前
千问Qwen-AgentWorld来了:一个语言模型搞定七大Agent场景,GPT-5.4都输了
算法
七牛开发者2 天前
MCP 到底是什么?为什么 Agent 都想接上它
算法·aigc·agent
卷无止境2 天前
C++ 的Eigen 库全解析
c++