#include #include #include const int dim = 4; int A[dim] = {1,2,3,4}; int B[dim] = {7,-1,2,5}; int C[dim]; void vector_print(int vec[]){ cout << "("; for (int x=0; x < dim-1; ++x) cout << vec[x] << ","; cout << vec[dim-1] << ")\n"; } void* add(void* param){ cout << "testing\n"; int p = *(int*)param; C[p] = A[p] + B[p]; pthread_exit(0); } int main(){ pthread_t tid[dim]; // thread id's for dim threads int x; int pos[dim]; for (x=0; x < dim; ++x){ pos[x] = x; pthread_create (&tid[x], NULL, add, &pos[x]); } // now threads run independently // wait for the threads to join for (int x=0; x < dim; ++x) pthread_join(tid[x], NULL); // print results cout << "The vector sum of\n"; vector_print(A); cout << "and\n"; vector_print(B); cout << "is\n"; vector_print(C); }