Programming tutorials online .NET, Java, C++, Visual Basic, and More
 

Home
.NET Tutorials
General Programming Tutorials
Community/Forums
Site Extras

 

C/C++ Forum
 

Open forum for posting questions or comments regarding C/C++.


POST REPLY
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!!!!!!



 
Sign In
Email
Password
  Forgot my password

Search

Featured Book

Code Complete, Second Edition ($27.49)
Code Complete, Second Edition


Featured Software

Microsoft Visual Studio Standard 2005 ($267.99)
Microsoft Visual Studio Standard 2005





 
© 2022 Ammastore.org
All Rights Reserved
COMPUTER SCIENCE HOMEWORK | Privacy/Disclaimer