【发布时间】:2011-04-14 00:43:27
【问题描述】:
所以我试图让线程启动函数打开一个通过命令行提供的文件,每个线程一个文件,但我还需要启动函数来获取我的结果数组。所以基本上我需要一个字符串(文件名)和一个二维结果数组到我的启动线程中,我完全糊涂了。
有人有什么建议或想法吗?谢谢。
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include "string.h"
void* func(void *args);
int main(int argc, const char * argv[])
{
int nthreads = 0;
int i = 0;
long **results;
printf("Enter number of threads to use:\n> ");
scanf("%d", nthreads);
pthread_t threadArray[nthreads];
// results 2d array; 3 rows by nthreads cols
results = malloc((nthreads*4) * sizeof(long *));
for(i = 0; i<nthreads; i++) {
pthread_create(&threadArray[i], NULL, wordcount, HELP!!!!);
}
for(i = 0; i<nthreads; i++) {
pthread_join(threadArray[i], NULL);
}
pthread_exit();
}
void * func(void *arguments)
{
FILE *infile = stdin;
infile = fopen(filename, "rb");
fclose (infile);
}
【问题讨论】:
标签: c arrays function pthreads startup