English 中文(简体)
多读: 开始和外围
原标题:Multithreading: When to Start and Exit threads

上,我稍加关注。 这项活动,而且我无法确定我是否应当对我更新的法典作出答复,把我原来的职位推给我,或提出一个新问题。 如果我没有遵守议定书,请提供咨询意见。

我迄今为止所做的工作已反映在投入文件中,并将所有愤怒分配给一个阵列。 然后,我把ger的总数(index)与read的数量( number_of_threads)区分开来,以便找到最佳的编号_per_thread

然后,我开始通过阵列中的所有数字进行加固,根据最佳号——每个批号——

prob_5.c

#include <stdio.h>

int main(int argc, char *argv[]) {
int i, j;
FILE *fp;
int values[15000];
char line[32];
int index = 0;
int number_of_threads = 10;
int numbers_per_thread;

for (i = 1; i < argc; i++) {
    fp = fopen(argv[i], "r");

    if (fp == NULL) {
        fprintf(stderr, "cat: can t open %s
", argv[i]);
        continue;
    }

    while (fgets(line, sizeof(line), fp) != NULL && (index < 15000)) {
        sscanf(line, "%d", &values[index]);
        index++;
    }

    fclose(fp);
}

numbers_per_thread = index / number_of_threads;

while (i < index) {
    for (j = 0; (j < numbers_per_thread) && (i < index); j++) {

        i++;
        j++;
    }
}

printf("%d
", index);

return 0;
}

我对我如何着手和阻止read子感到困惑。 我是否应该开始在座(j = 0; .)路段内,然后创造(j = 号码_per_thread)来结束路面? 我是否应当建立一个新阵列,以容纳每一条路面的号码? 我猜想,我对如何使用read子——create、pthread_join等感到困惑。 这是我第一次尝试使用这些工具。

问题回答

我将作一系列的<代码>pthread_t。 储存你所创造的每条read子的价值。 在你阅读了各种价值观之后,就在一旁创造这些价值观,然后立即再做一次尝试,以加入所有价值观。 之后,你可以单独提取部分款项,并加起来,获得最后一笔款项。





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签