Hi :]
First time on the forums, and i did try to do a search on google but got no help for for it.
Unless i searched the wrong thing but here it goes.
I already wrote this program in class and it works at the unix lab in my school. I just installed FC3 on my pc and did all the updates. But yet the program will not compile on my home pc.
Here is the code for the program
Code:
4 4 #include <pthread.h>
5 5 #include <iostream.h>
6 6 #include <stdlib.h>
7 7 #include <unistd.h>
8 8
9 9 void *run(void *param);
10 10
11 11 int main(int argc, char *argv[])
12 12 {
13 13 //First we take the input of argv[1] and convert it to an integer type.
14 14 //Also iCounter will be our counter for amount of threads.
15 15 int iAmtOfThrds = atoi(argv[1]), iCounter;
16 16
17 17 pthread_t tid[100]; //Thread id array for 'x' amount of threads.
18 18 pthread_attr_t attr; //Thread attributes
19 19 attr_init(&attr); //Initial thread attributes
20 20
21 21 //Start for...loop to create 'x' amount of threads
22 22 //Then pass it to the run() function.
23 23 for(iCounter = 0; iCounter < iAmtOfThrds; iCounter++)
24 24 pthread_create(&tid[iCounter], &attr, run, argv[1]); //Create a new thread multiple times
25 25
26 26 //Start for...loop to wait for each thread to finish
27 27 for(iCounter = 0; iCounter < iAmtOfThrds; iCounter++)
28 28 pthread_join(tid[iCounter], NULL); //Wait for the new thread to finish
29 29 }
30 30
31 31 /*
32 32 This function we pass the argv[1] and
33 33 let the thread sleep for 10 seconds.
34 34 */
35 35 void *run(void *param)
36 36 {
37 37 cout << "Starting New Thread.\n";
38 38 sleep(10);//System Call to let the thread sleep for 10 seconds.
39 39 cout << "Thread finished, exiting function.\n";
40 40 pthread_exit(0);//Exits thread.
41 41 }
But i get the following errors:
Quote:
$ g++ thread.c -lpthread -o thread.out
thread.c:1: error: expected unqualified-id before numeric constant
thread.c:1: error: expected `,' or `;' before numeric constant
thread.c:4: error: invalid token
thread.c:5: error: invalid token
thread.c:6: error: invalid token
thread.c:7: error: invalid token
thread.c:10: error: expected unqualified-id before numeric constant
thread.c:10: error: expected `,' or `;' before numeric constant
thread.c:30: error: expected unqualified-id before numeric constant
thread.c:30: error: expected `,' or `;' before numeric constant
thread.c:42: error: expected unqualified-id before numeric constant
thread.c:42: error: expected `,' or `;' before numeric constant
|
is there something that i do not have installed on this linux? at first i thought maybe i didn't have pthread.h but then it would have said something about not being able to find it.
Any help would be great b/c i'd like to work on it at home instead of going to school or working through ssh.
Thank you :]