Fibonacci sequence using pthreads

Hello, I am new to pthreads and trying to complete this homework assignment:
Write a multithreaded program that generates the Fibonacci sequence using either the Java, Pthreads, or Win32 thread library. This program should work as follows: The user will enter on the command line the number of Fibonacci numbers that the program is to generate. The program will then create a separate thread that will generate the Fibonacci numbers, placing the sequence in data that can be shared by the threads (an array is probably the most convenient data structure). When the thread finishes execution, the parent thread will output the sequence generated by the child thread. Because the parent thread cannot begin outputting the Fibonacci sequence until the child thread finishes.
I keep getting this linker error below. Not sure how to resolve it and make this code run.

Linker errors:
1>thread.obj : error LNK2019: unresolved external symbol __imp__pthread_join referenced in function _main
1>thread.obj : error LNK2019: unresolved external symbol __imp__pthread_create referenced in function _main
1>thread.obj : error LNK2019: unresolved external symbol __imp__pthread_attr_init referenced in function _main
1>C:\Users\delon_000\Dropbox\Operating Systems\delongkevin_multiThreads\Debug\delongkevin_multiThreads.exe : fatal error LNK1120: 3 unresolved externals

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <pthread.h>
#include <cstdlib>
#include <stdio.h>
#include <iostream>
#include <sys/types.h>
#include <Windows.h>

int shared_data[10000];

void *fibonacci_thread(void* params);
void parent(int* numbers);

 int main() {

	int numbers = 0; //user input.

	pthread_t child; // create thread
	pthread_attr_t attr; 
	pthread_attr_init(&attr); 

	parent(&numbers); // get user input then start separate thread.
	pthread_create(&child, &attr, fibonacci_thread, (void*) &numbers); //starts fibonacci thread
	pthread_join(child, NULL); //waits for thread to finish

	//output to command prompt after thread finishes.
	for(int i = 0; i <= shared_data[i]; i++) {
		printf("%d",shared_data[i]);
	}

	return 0;
 }

void *fibonacci_thread(void* params) {
	
	int fib0 = 0, fib1 = 1, next = 0;
	int *pointer;
	pointer = (int*) params;
	int total = *pointer;
	
	for (int i = 0 ; i < total; i++ ) {
      if ( i <= 1 )
         next = i;
      else {
         next = fib0 + fib1;
         fib0 = fib1;
         fib1 = next;
      }
	  next = shared_data[i]; //store to shared_data array
	}
	//pthread_exit(0);
	return NULL;
}

void parent(int* numbers) {
	std::cout<<"Enter in a number to generate the Fibonacci sequence: ";
	std::cin>>*numbers;

	while(isdigit(*numbers) != true) {
		std::cout<<"Invalid character, please enter in a number: ";
		std::cin>>*numbers;
	}

	return;
}
Topic archived. No new replies allowed.