[图像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;
}
相关推荐
Halo_tjn35 分钟前
Java 基于字符串相关知识点
java·开发语言·算法
梦想的颜色40 分钟前
java 利用redis来限制用户频繁点击
java·开发语言
报错小能手42 分钟前
Swift 并发 Combine响应式框架
开发语言·ios·swift
念越1 小时前
算法每日一题 Day08|双指针法解决三数之和
算法·力扣
万法若空1 小时前
C++ <memory> 库全方位详解
开发语言·c++
黎阳之光1 小时前
黎阳之光透明管理:视频孪生重构智慧仓储新范式
人工智能·算法·安全·重构·数字孪生
代码中介商1 小时前
C++ 类型转换深度解析:static_cast、dynamic_cast、const_cast、reinterpret_cast
开发语言·c++
青小莫1 小时前
C++之string(OJ练习)
开发语言·c++·stl
freshman_y1 小时前
一篇介绍C语言中二级指针和二维数组的文章
c语言·开发语言
6Hzlia1 小时前
【Hot 100 刷题计划】 LeetCode 199. 二叉树的右视图 | C++ DFS 逆序遍历
c++·leetcode·深度优先