Posted By: johngr |
1/10/2007 5:23:00 AM |
|
|
Help with pthreaDS?
hELLo!
I have an array A[10] and 2 threads. The thread_1 adds +1, in the first 5 elements of the array A[0,1,2,3,4} and then the thread_2 subtract -2 in the last 5 elements of the array A{5,6,7,8,9}.
i kave written this:
#include
#include
#define NUM_THR 2
#define meg_A 10
int i,A[10];
void *func1(void *threadid)
{
for(i=0; i
{
A[i] = i +1;
}
pthread_exit(NULL);
}
void *func2(void *threadid)
{
for(i= (meg_A/2); i
{
A[i] = i - 2;
}
pthread_exit(NULL);
}
int main()
{
pthread_t threads[NUM_THR];
int t,i, A[10], B[10];
for(i=0; i
{
A[i] = i;
printf("%d\n", A[i]);
}
printf("\n\n");
for (t=0; t
{
if(t=0)
{
pthread_create(&threads[t], NULL, func1, (void *)t );
}
else
{
pthread_create(&threads[t], NULL, func2, (void *)t );
}
for(i=0; i
{
printf("%d \n",A[i]);
}
return 0;
}
}
Can anyone tell me what i have written wrong????
thxxxxxxxxxxxxxxxxxx!!!!!!
|
|