Thursday, July 30, 2009

C programming threads and array?

I have 30 sets of number stored in an array. i created 3 threads to handle the number. Therefore each thread will handle 10 sets of number.





How do i make sure that each thread will handle 10 different number without overlapping the other threads?





Basically each thread will compute and find the smallest number within the set itself....

C programming threads and array?
Have your thread spawn process take the array, the index to begin at and the length to scan as parameters. If I recall correctly, you can only pass 1 parameter to a thread, so create a struct like this:





typedef struct THREAD_DATA


{


int *ptr; // pointer to array


int startIndex; // index to start from


int length; // length to read


}





Fill that out and pass it to each thread.

wedding florist

No comments:

Post a Comment