[图像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;
}
相关推荐
破茧蝴蝶7 小时前
Python分布式爬虫完整教程
开发语言·python
狗凯之家源码网7 小时前
全新 PHP 轻量客服聊天室源码深度评测
开发语言·php·聊天室系统
远离UE47 小时前
UE5 Substrate Thin Film 源码拆析
开发语言·javascript·ue5
keyipatience8 小时前
JavaScript学习(1)书写位置,变量、数据类型、运算符
开发语言·前端·javascript·css·学习
hanlin038 小时前
刷题笔记:力扣第32题-最长有效括号
笔记·算法·leetcode
一拳一个呆瓜8 小时前
【STL】文件系统导航
c++·stl
All for pursuit.8 小时前
【动态规划-21】312.戳气球
数据结构·c++·算法·leetcode·动态规划
栈帧之外8 小时前
【C++】STL之set
开发语言·c++
catchadmin9 小时前
免费可商用 PHP 管理后台 CatchAdmin V5.4.1 发布,新增 MCP 支持
开发语言·php
zhanghaha13149 小时前
C++构造函数的一些其他应用(逐词逐句保姆讲解)
c++