[图像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;
}
相关推荐
AI_56781 天前
接口测试“零基础通关“:Postman从入门到自动化测试实战指南
开发语言·lua
kupeThinkPoem1 天前
哈希表有哪些算法?
数据结构·算法
是Yu欸1 天前
Rust 并发实战:从零构建一个内存安全的“番茄时钟”
开发语言·安全·rust
小白程序员成长日记1 天前
2025.11.16 力扣每日一题
算法
Justinyh1 天前
1、CUDA 编程基础
c++·人工智能
应用市场1 天前
Qt QTreeView深度解析:从原理到实战应用
开发语言·数据库·qt
ooooooctober1 天前
PHP代码审计框架性思维的建立
android·开发语言·php
Kuo-Teng1 天前
LeetCode 118: Pascal‘s Triangle
java·算法·leetcode·职场和发展·动态规划
Greedy Alg1 天前
LeetCode 32. 最长有效括号(困难)
算法
864记忆1 天前
Qt Widgets 模块中的函数详解
开发语言·qt