I actually tried that, well, I got weird results. I'm making a problem that keeps count of the word with the highest frequency. Say, the finding part is within
void *find_t(void *arg)
Assume it works. Cause it works fine when I create the thread and then use pthread_join after like so:
Code:
for(t=1; t<argc;t++)
{
pthread_create(&thread[t], &attr, find_t, argv[t]);
pthread_join(thread[t],NULL);
temp[t-1]->freq = words[0]->freq;
}
But if I do it like concurrently, I bump into a problem, it works fine if I read in one file, but I want to read multiple files frequent word and end up getting an obscurely large number which I believe may be the frequency of all the files.
Code:
for(t=1; t<argc;t++)
{
pthread_create(&thread[t], &attr, find_t, argv[t]);
temp[t-1]->freq = words[0]->freq;
}
int q;
for(q=1; q<argc;q++)
{
pthread_join(thread[q],NULL);
temp[q-1]->freq = words[0]->freq;
}
Any suggestion?
EDIT:
More precisely, if I were to input a.out filename1 filename2
i would want two numbers,
freq of filename1, freq of filename2
what I'm actually getting is
obscurely large number of one of the two files, another obscurely large number of one of the two files(or the same number as the former)