-
Notifications
You must be signed in to change notification settings - Fork 0
/
thread_func.c
29 lines (28 loc) · 877 Bytes
/
thread_func.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "thread_func.h"
#include <stdio.h>
#include <stdlib.h>
void *thread_func(void *args)
{
// Convert the function argument to a pointer to a structure
struct thread_args *st_args = (struct thread_args *)args;
// Total result of summing the sequence elements from all threads
unsigned long long res = 0;
FILE *input = NULL;
unsigned long long number;
input = fopen("fib.bin", "rb");
if (input == NULL) {
printf("Error opening file");
exit(1);
}
int begin = st_args -> index_start;
int end = st_args -> index_end;
fseek(input, begin * sizeof(long long), SEEK_SET);
for(begin; begin < end; begin++){
fread(&number, sizeof(long long), 1, input);
printf("Thread %d: %lld\n",st_args -> id, number);
res += number;
}
st_args -> res = res;
fclose(input);
return NULL;
}